2012-03-16 3 views
0

私はjsonファイルを解析し、それをテーブルビューに埋め込んでいます。 Var tycker duという名前の私のテーブルビューです。しかしso.itは、jsonファイルから動的に割り当てられたデータをオーバーラップさせます。テーブルビューで動的に割り当てられたデータの最初と最後の行に静的な行を割り当てる方法

static NSString * const kCellTextKey = @"CellTextKey"; 
static NSString * const kCellStateKey = @"CellStateKey"; 

static NSString* kAppId = @"126013844184727"; 
#define KFBAccessToken  @"126013844184727" 
    #define KFBExpirationDate @"KFBExpirationDate" 

    @implementation Tab5 

    @synthesize tableview1,jsonData,jsonArray,story,media1,url,descriptiondesc,media2; 
    @synthesize arForIPs = _arForIPs; 
    - (void)viewDidLoad { 
    [super viewDidLoad]; 
objMan = [[HJObjManager alloc] initWithLoadingBufferSize:6 memCacheSize:20]; 
self.arForIPs=[NSMutableArray array]; 


    self.tableview1.backgroundColor=[UIColor clearColor]; 
[self.tableview1 setAllowsSelectionDuringEditing:TRUE]; 

jsonurl=[NSURL URLWithString:@"http://dev-parkguiden.knutpunkten.se/Api/GetPark? parkid=3"]; 
NSURLRequest *request = [NSURLRequest requestWithURL:jsonurl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; 
connection1=[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease]; 

self.jsonData=[NSData dataWithContentsOfURL:jsonurl]; 

NSDictionary *items=[NSJSONSerialization JSONObjectWithData:self.jsonData options:NSJSONReadingMutableLeaves error:nil]; 

items1 = [items objectForKey:@"ThingsTodo"]; 

story = [[NSMutableArray array]retain]; 
media1 = [[NSMutableArray array]retain]; 

url=[[NSMutableArray array]retain]; 
media2=[[NSMutableArray array]retain]; 
descriptiondesc=[[NSMutableArray array]retain]; 
dog=[[NSMutableArray array]retain]; 
arr=[[NSMutableArray array]retain]; 
bose=[[NSMutableArray array]retain]; 
for (NSDictionary *item in items1) 
{ 
    [self.story addObject:[item objectForKey:@"Name"]]; 
    [self.media1 addObject:[item objectForKey:@"Status"]]; 
    //[self.media2 addObject:[item objectForKey:@"Image"]]; 

} 

//NSLog(@"room:%@",items1); 
[self makeNewArray]; 


    } 


    -(void)makeNewArray 
    { 
    for (int i=0; i<[self.media1 count]; i++) 
    { 

    NSDictionary *boy=[self.media1 objectAtIndex:i]; 



    NSString *str=[[NSString alloc]initWithFormat:@"%@",boy]; 
    //NSLog(@"the value:%@",str); 

    if([str isEqualToString:@"1"]) 
    { 
     text = [self.story objectAtIndex:i]; 
     NSString *text1 = [NSString stringWithFormat:@"%@",text]; 
     NSNumber *state = [NSNumber numberWithBool:NO]; 


    dict=[NSDictionary dictionaryWithObjectsAndKeys:text1,kCellTextKey,state,kCellStateKey,nil]; 
     [arr addObject:dict]; 



    // [dog addObject:[self.story objectAtIndex:i]]; 


    } 
    dog=[arr mutableCopy]; 
     NSLog(@"wat hav i got:%@",arr); 

    } 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 

return 1; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

{ 

return [dog count]; 

} 

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } 
// cell.textLabel.text=[dog objectAtIndex:indexPath.row]; 
NSDictionary *rowData = [dog objectAtIndex:indexPath.row]; 
cell.textLabel.text = [rowData objectForKey:kCellTextKey]; 
if ([[rowData objectForKey:kCellStateKey] boolValue]) { 
    cell.accessoryType = UITableViewCellAccessoryCheckmark; 
} else { 
    cell.accessoryType = UITableViewCellAccessoryNone; 
    [bose removeObject:[newDict valueForKey:@"CellTextKey"]]; 
    // NSLog(@"object going to get removed:%@",bose); 
} 
sectionRows = [tableview1 numberOfRowsInSection:[indexPath section]]; 



return cell; 

    } 

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
NSDictionary *dict = [dog objectAtIndex:indexPath.row]; 
BOOL newState = ![[dict objectForKey:kCellStateKey] boolValue]; 
newDict = [NSDictionary dictionaryWithObjectsAndKeys:[dict objectForKey:kCellTextKey], kCellTextKey, [NSNumber numberWithBool:newState], kCellStateKey, nil]; 
[dog replaceObjectAtIndex:indexPath.row withObject:newDict]; 

[bose addObject:[newDict valueForKey:@"CellTextKey"]]; 
NSLog(@"the current added data:%@",bose); 
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; 

    } 
    } 

答えて

1

ちょっとこの溶液で

-(void)makeNewArray 
{ 
for (int i=0; i<[self.media1 count]; i++) 
{ 

    NSDictionary *boy=[self.media1 objectAtIndex:i]; 
    NSString *str=[[NSString alloc]initWithFormat:@"%@",boy]; 
    //NSLog(@"the value:%@",str); 

    if([str isEqualToString:@"1"]) 
    { 
     text = [self.story objectAtIndex:i]; 
     NSString *text1 = [NSString stringWithFormat:@"%@",text]; 
     NSNumber *state = [NSNumber numberWithBool:NO]; 


     dict=[NSDictionary dictionaryWithObjectsAndKeys:text1,kCellTextKey,state,kCellStateKey,nil]; 
     [arr addObject:dict]; 

     // [dog addObject:[self.story objectAtIndex:i]]; 
    } 
} 
NSDictionary *dict; 

dict = [NSDictionary dictionaryWithObjectsAndKeys: 
     @"Var tycker du", @"CellTextKey", 
     @"0", @"CellStateKey", nil]; 
[dog addObject:dict]; 
for(int i=0; i<arr.count; i++){ 
    [dog addObject:[arr objectAtIndex:i]]; 
} 


[dog addObject:dict];   
//  dog=[arr mutableCopy]; 
NSLog(@"wat hav i got:%@",dog); 


} 
を試してみます
関連する問題