I have my custom class Users which have several fields. e.g. username, password, first name, last name.
我的自定义类用户有几个字段。例如用户名、密码、名、姓。
i have an object of Users class user. when i want to set the text of UILabel of UITableviewCell it giving me the following exception:
我有一个user类user的对象。当我想设置UITableviewCell的UILabel的文本时它给了我以下的例外:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary firstName]: unrecognized selector sent to instance 0x755f510'
终止应用程序由于未捕获异常'NSInvalidArgumentException',原因:'-[__NSCFDictionary firstName]:未识别的选择器发送到实例0x755f510'
my code is:
我的代码是:
self.user = [usersArray objectAtIndex:indexPath.row];
((UILabel *)[cell viewWithTag:19]).text = user.firstName;
((UILabel *)[cell viewWithTag:20]).text = user.lastName;
((UILabel *)[cell viewWithTag:21]).text = user.username;
1 个解决方案
#1
0
I have done it by using NSDictionary. I passed the object of my custom class to NSDictionary and then set the text of UITableviewCell through NSDictionary.
我是用NSDictionary的。我将自定义类的对象传递给NSDictionary,然后通过NSDictionary设置UITableviewCell的文本。
NSDictionary *dictionary = (NSDictionary *)[usersArray objectAtIndex:indexPath.row];
((UILabel *)[cell viewWithTag:19]).text = [dictionary objectForKey:@"firstName"];
((UILabel *)[cell viewWithTag:20]).text = [dictionary objectForKey:@"firstName"];
((UILabel *)[cell viewWithTag:21]).text = [dictionary objectForKey:@"firstName"];
#1
0
I have done it by using NSDictionary. I passed the object of my custom class to NSDictionary and then set the text of UITableviewCell through NSDictionary.
我是用NSDictionary的。我将自定义类的对象传递给NSDictionary,然后通过NSDictionary设置UITableviewCell的文本。
NSDictionary *dictionary = (NSDictionary *)[usersArray objectAtIndex:indexPath.row];
((UILabel *)[cell viewWithTag:19]).text = [dictionary objectForKey:@"firstName"];
((UILabel *)[cell viewWithTag:20]).text = [dictionary objectForKey:@"firstName"];
((UILabel *)[cell viewWithTag:21]).text = [dictionary objectForKey:@"firstName"];