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