0
后我具有从一个JSON调用每5秒刷新加载值的表。每当表更改时,添加新单元格时,当前选定的单元格将成为重新加载的最后一个单元格上方的单元格。你可以在我的get_counter选择器中看到我正在尝试执行的操作。提前致谢!我还是很新的ObjC所以只是想学习:)保持UITableView的选择的值的数据重新加载
- (void)viewDidLoad {
[super viewDidLoad];
repeat_timer=[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(check_new) userInfo:nil repeats:YES];
}
-(void)check_new{
NSString *ret;
ret=[MyWebFunction is_new_orders:appDelegate.user_id Order_number:[[response_array objectAtIndex:0] objectForKey:@"order_id"] Type:type];
if([ret isEqualToString:@"yes"]){
[indicator startAnimating];
[self performSelector:@selector(get_counter) withObject:nil afterDelay:0.0005];
}
}
-(void)get_counter{
jsonString = [[NSMutableString alloc] initWithData:[MyWebFunction get_orders:appDelegate.user_id Type:type Limit:limit] encoding:NSUTF8StringEncoding];;
response_array = [[jsonString JSONValue] retain];
[indicator stopAnimating];
//this is my attempt at retaining the value :)
NSIndexPath *ipath = [table indexPathForSelectedRow];
NSLog(@"iPath: %@",ipath);
[table reloadData];
[table selectRowAtIndexPath:ipath animated:NO scrollPosition:UITableViewScrollPositionNone];
if([response_array count]>0){
total=[[[response_array objectAtIndex:0] objectForKey:@"total_orders"] intValue];
checksArray=[[NSMutableArray alloc] init];
for(int i=0;i<response_array.count;i++){
[checksArray addObject:@"0"];
}
}
sel_item_id=[[NSMutableArray alloc] init];
all_ids=nil;
if(repeat_timer){
[repeat_timer invalidate];
repeat_timer=nil;
repeat_timer=[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(check_new) userInfo:nil repeats:YES];
}
}
谢谢Jaybit ...虽然没有工作。 :( 当我做一个NSAPI的IPATH,它会出现为空,所以它可能是它在不同的类,该行被选中或什么? –
“indexPathForSelectedRow 返回一个索引路径标识的行和部分 - (NSIndexPath *)indexPathForSelectedRow 返回值 标识选定行的行和段索引的索引路径,如果索引路径无效,则返回nil。“来自UITableView CLass Reference – Jaybit