25 iphone uitableview ios
首先,这次讨论没有解决我的问题.
自定义UITableViewCell子类:此类不是符合编码规范的键值
建立:
我有一个Person对象数组MainViewController
.要显示在一个对象UITableView
中AllContactsViewController
.
问题:
使用默认值时,所有工作都按预期工作UITableViewCell
.当我使用我的自定义时,TableCell
我得到一个错误,指出该类不符合键值编码.
我连接我的任何三个之后会出现此错误outlets
在IB
我的TableCell
班.
注意:
TableCell
有三个属性:a name
&email
label + imageView
.
希望你能帮忙.
TableCell.h
#import <UIKit/UIKit.h>
@interface TableCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *emailLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
Run Code Online (Sandbox Code Playgroud)
TableCell.m
#import "TableCell.h"
@implementation TableCell
@synthesize nameLabel, imageView, emailLabel;
Run Code Online (Sandbox Code Playgroud)
AllContactsViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdent = @"TableCell";
TableCell *cell = (TableCell *)[tableView dequeueReusableCellWithIdentifier:cellIdent];
if (cell == nil) {
NSArray *array = [[NSBundle mainBundle]loadNibNamed:@"TableCell" owner:self options:nil];
cell = [array objectAtIndex:0];
}
NSString *firstAndLastnameString =
[NSString stringWithFormat:@"%@ %@",
[(NewContact *)[self.allContactsArray objectAtIndex:[indexPath row]] firstName],
[(NewContact *)[self.allContactsArray objectAtIndex:[indexPath row]] lastName]];
cell.nameLabel.text = firstAndLastnameString;
cell.emailLabel.text =
[(NewContact *)[self.allContactsArray objectAtIndex:[indexPath row]] eMail];
cell.imageView.image =
[(NewContact *)[self.allContactsArray objectAtIndex:[indexPath row]] contactPicture];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
更新:
也许截图可以帮助IB.
添加了完整的AllContactsViewController.h
#import <UIKit/UIKit.h>
#import "VCDelegate.h"
#import "TableCell.h"
@interface AllContactsViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) id <VCDelegate>delegate;
@property (weak, nonatomic) IBOutlet UITableView *allContactsTableView;
@property (strong, nonatomic) NSMutableArray *allContactsArray;
@property (assign) int currentArrayIndexNumber;
- (IBAction)closeBtnTapped:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)
Nat*_* R. 61
如果您要连接文件所有者的插座,您应该做不同的事情:
1 - 为您的TableCell类定义UITableViewCell的类:
2 - 不是从文件所有者连接插座,而是从对象列表中的TableCell连接插座:
我的项目中的一切都完成了,并且在尝试使用自定义单元及其属性时仍然收到了。这是我如何解决我的问题的。
CustomUITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomUITableViewCell" forIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)
真正让我震惊的是简单地CustomUITableViewCell
从自定义单元格的“身份检查器”中删除该类并重新输入它..您将看到更改
让它们成为自动出现的值...不要尝试继承它或更改继承或模块值...