如题,相关代码如下
//在按下该按钮时要求改变tableview其中一行的文本
- (IBAction)inputCMDEnter:(UIButton *)sender {  
    NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    UITableViewCell *cell = [tableCMDView cellForRowAtIndexPath:indexPath];
    cell.textLabel.text = @"123";
}//代理相关的函数
- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
    return 15;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *SimpleTableIdentifier = @"COMMANDS";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:SimpleTableIdentifier];
    }
    NSUInteger row = [indexPath row];
    cell.textLabel.text = [listData objectAtIndex:row];
    return cell;
}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}在connections inspecors中,已经将tableview的datasource和delegate关联到files owner了。
可是tableview中的文本一直没有改变,弄了一下午了,求解决方法

解决方案 »

  1.   

    你应当改变你dataSource中对应该行的数据,然后使用
    - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);这个方法来reload该行
      

  2.   


    不能直接这样改吗?- (IBAction)inputCMDEnter:(UIButton *)sender {  
        NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
        UITableViewCell *cell = [tableCMDView cellForRowAtIndexPath:indexPath];
        cell.textLabel.text = @"123";
    }我看到apple提供的一个示例代码就是这样写的。那个工程可以这样找到,打开xcode帮助文档,搜索uitableview,左下角那个datecell就时了。麻烦帮忙看一下,不知道apple是怎么做到的。我刚开始写这种程序,不太懂。
      

  3.   

    不介意的话你把CODE发我给你看一下,[email protected]
      

  4.   

    你设定了 新得数值,最好是 让 tableView 重新 绘制一下(可以整个表 重绘reloaddata,也可以是section,也可以是row)
    而且,重绘得时候,会调用
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

      这里,你得cell.textlabei.text 又会 执行一边 取数值操作。很令人蛋疼得。
      

  5.   

    按你写的代码,应该说是可以的。但不知道你那边为什么看不到效果。
    不过还有一种方法可以偿试,就是:修改指定行的数据源,然后再reloadRow- (IBAction)inputCMDEnter:(UIButton *)sender {  
        int rowIndex=0;
        NSIndexPath * indexPath = [NSIndexPath indexPathForRow:rowIndex inSection:0];
        NSString *title=[listData objectAtIndex:rowIndex];
        title=@"123";
        [listData replaceObjectAtIndex:indexPath withObject:title];    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
                                                       withRowAnimation:YES];
        
    }
      

  6.   

    NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
        UITableViewCell *cell = [tableCMDView cellForRowAtIndexPath:indexPath];
        cell.textLabel.text = @"123";
     [cell setNeedDisplay]; 试试
      

  7.   


    //刷新表数据,最简单有效的方法,暂不考虑性能
    [talbeView reloadData];