如题,相关代码如下
//在按下该按钮时要求改变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中的文本一直没有改变,弄了一下午了,求解决方法
//在按下该按钮时要求改变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中的文本一直没有改变,弄了一下午了,求解决方法
解决方案 »
- 关于图片截取时的内存泄露问题
- 自己编写的iphone应用程序A如何拉起另外一个应用程序B?
- xcode4.0 发布应用程序 crash
- 高度自定义 UITabBarController, 支持StoryBoard
- ios开发,图片问题
- uiwebview加载图片的问题
- iOS蓝牙3.0扫描枪开发
- 以上普通的json如何以这种方式展示
- ios webview 使用loadHTMLString方法加载html数据 怎么异步加载出图片?
- 请问可以用Video toolbox 实现网络视频的转码吗? flv->mp4
- 编译出来的静态库,真机上运行报错
- uiview中addsubview,不显示加入的view
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);这个方法来reload该行
不能直接这样改吗?- (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是怎么做到的。我刚开始写这种程序,不太懂。
而且,重绘得时候,会调用
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
这里,你得cell.textlabei.text 又会 执行一边 取数值操作。很令人蛋疼得。
}
不过还有一种方法可以偿试,就是:修改指定行的数据源,然后再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];
}
UITableViewCell *cell = [tableCMDView cellForRowAtIndexPath:indexPath];
cell.textLabel.text = @"123";
[cell setNeedDisplay]; 试试
//刷新表数据,最简单有效的方法,暂不考虑性能
[talbeView reloadData];