5秒ごとに更新されるJSON呼び出しから値を読み込んでいるテーブルがあります。テーブルが変更され、新しいセルが追加されるたびに、現在選択されているセルが、リロード時に最後のセルより上のセルになります。get_counterセレクターで、私がそれを実行しようとしている場所を確認できます。前もって感謝します!私はまだObjCで非常に新しいので、ただ学ぼうとしています:)
- (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];
}
}