开发者

How to access a member object

开发者 https://www.devze.com 2023-01-16 07:35 出处:网络
I have made a custom object called students that has two nsstring object. One is for the name and the other for the student id. If I try to pass the custo开发者_如何学Gom object to something that take

I have made a custom object called students that has two nsstring object. One is for the name and the other for the student id. If I try to pass the custo开发者_如何学Gom object to something that takes nsstring, it doesn't work. I want to pass the name. How can I do this?


You can nest your method calls like this:

cell.textLabel.text = [[studentArray objectAtIndex:indexPath.row] name];

Or if you defined your members as properties and want to access them via dot-notation:

cell.textLabel.text = [studentArray objectAtIndex:indexPath.row].name;

The only issue with the dot-notation approach is the compiler will most likely give you warning that it couldn't find the property name, so you will need to cast it to the appropriate data type before accessing the property via dot-notation.

0

精彩评论

暂无评论...
验证码 换一张
取 消