2011-12-27 15 views
1

各セルに配列の動的データが入力されるテーブルビューがあります。ここから、ユーザーが行を選択すると、そのセルからViewControllerに特定のデータをプッシュして、最終的にPOST要求に使用できるようにしたいと考えています。今私のtableviewcontroller上のこのコードは、データを表示するだけですUITableViewで選択したセルからデータを渡す

実際にどのようにデータを使用しますか?ここで

は、私は(実際のコードは、複数のNSMutableArraysを持っているが、私は一つだけを含む)持っているものの抜粋です:

 - (void)viewDidLoad 
    { 

     [super viewDidLoad]; 
     photoTitles = [[NSMutableArray alloc] init]; 
NSURL *url = [NSURL URLWithString:@"http://localhost/test.php"]; 
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 
    [request setPostValue:dataCenter.data forKey:@"name"]; 
    [request setDelegate:self]; 
    [request startAsynchronous]; 

} 
- (void)requestFinished:(ASIFormDataRequest *)request 
{ 

    NSString *responseString = [request responseString]; 

    NSDictionary *dictionary = [responseString JSONValue]; 
    NSArray *photos = [[dictionary objectForKey:@"photos"] objectForKey:@"photo"]; 

    for (NSDictionary *photo in photo) { 
     NSString *photo = [photo objectForKey:@"photo"]; 
     [photoTitles addObject:photo]; 
    }  
} 

-(NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section 
{ 
    return [photoTitles count]; 
} 

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


    static NSUInteger const kPhotoTitleTag = 2; 
    UILabel *photoTitleLabel = nil; 

static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: 
          SimpleTableIdentifier]; 
    if(cell == nil){ 


     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: SimpleTableIdentifier]; 

     photoTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 25, 170, 14)]; 
     [cell.contentView addSubview:photoTitleLabel]; 
}else { 
     photoTitleLabel = (UILabel *)[cell.contentView viewWithTag:kPhotoTitleTag]; 
} 
NSUInteger row = [indexPath row]; 

    photoTitleLabel.text = [photoTitles objectAtIndex:row]; 
    return cell; 

正しい方向に私を置くことで任意のヘルプは素晴らしいだろう。何かが明確でない場合は、私に知らせてください。

+1

私は、あなたがDetailGameControllerのいくつかのインスタンス変数に渡したい日付を設定することはできませんか? – MadhavanRP

答えて

6

なぜ行のインデックスを渡すのですか?
他のコントローラが使用する必要のある情報を渡します。

DetailGameController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"]; 
NSUInteger row = [indexPath row]; 
detail.someProperty = [photoTitles objectAtIndex:row]; 
detail.someOtherProperty = // other interesting elements ; 
+0

.Xibを使ってこれを行う方法? – Muju

関連する問題