1
我有2个视图-view1和view2,一个用于输入数据,另一个用于显示输入的数据。 我可以在标签中的视图2中显示输入的数据。但是如何在UITableView中显示数据。以下是我的代码来显示数据:在UITableView中显示导航数据
view2.m
@synthesize details; //details is an object of NSMutableArray.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
textLabel.text = self.name;
lblCity.text = self.city;
lblGender.text = self.gender;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [details count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [details objectAtIndex:indexPath.row];
//cell.imageView.image = [UIImage imageNamed:@"creme_brelee.jpg"];
return cell;
我debuuged,发现cellForRowAtIndexPath
永远不会被调用。
我在哪里出错?我如何解决它?
难道ÿ你可以将tableView的'dataSource'和'delegate'设置为你的对象吗? –
对不起,但我是新来的ios,我如何设置它们? – z22
如果你在xib中使用了表,然后将它的委托方法设置为文件所有者。看到这个http://www.techotopia.com/index.php/Creating_a_Simple_iOS_4_iPhone_Table_View_Application_%28Xcode_4%29 – Dhara