2011-05-26 43 views
0

所以,我在下面发布我的代码。UITableViewController警告 - 帮助!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  // I get a warning here Incomplete method implementation // 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Configure the cell... 
    NSLog (@"Dobby4"); 
    NSInteger row = [indexPath row]; 
    cell.text = [dogArray objectAtIndex:row]; 

    //I get a warning for the line above-- 'text' is deprecated // 
    return cell; 
} 

所以,
1.我收到了警告 - 不完整的方法实现了该功能。
2.我得到另一个警告“文本”已弃用'
3.我试图调试,并试图打印一行“Dobby4” - 它没有打印。

我将不胜感激。

+0

感谢您编辑Deepak。现在看起来好多了! – Legolas 2011-05-26 17:57:04

回答

2
  1. 我怀疑它是用这个函数做的。可能是之前的方法。如果你把它放在代码清单中也会很好。
  2. 您不应该使用text属性来设置文本(正如警告所述,不建议使用)。使用cell的子视图textLabel。所以这条线将是cell.textLabel.text = [dogArray objectAtIndex:row];
  3. 由于它不打印Dobby4,您的numberOfSectionsInTableView:tableView:numberOfRowsInSection:返回0.如果不是这样,那么您没有正确连接数据源。
+0

嗨Deepak,修正2)谢谢!我通过在控制器中打印一些随机的东西来尝试调试SegmentInTableView的numberof,并且确实打印了。我认为它返回0; – Legolas 2011-05-26 18:09:52

+0

你建议我做什么? – Legolas 2011-05-26 18:10:02

+1

在数据源中实现我在(3)中提到的两种方法。返回1为'numberOfSectionsInTableView:'并返回'[dogArray count]'为'tableView:numberOfRowsInSection:'。 – 2011-05-26 18:18:50

0

1)编译器可能会呻吟,因为方法实现可能不会出现在您的头文件中,反之亦然?

2)UITableViewCell的.text属性从iOS 3.0开始确实被弃用,因此您将无法使用它,因为您确定定位到更高的iOS版本。

3)也许与1)有关。

希望这有一些帮助,让我们张贴!

+0

氪,关于1)和3) - 默认情况下,实现文件中包含方法实现,并且包含头文件。 – Legolas 2011-05-26 18:05:00