2012-02-21 6 views
0

テーブルセルに値を渡そうとしていますが、文字列をuserdata.titleに置き換えると、 は空白になります。 userdataは外部のUserDataという別のクラスのオブジェクトで、インポートします。 UserDataはすべてのビューからアクセスされ、あるコントローラから別のコントローラにオブジェクトを渡します。今、テーブルに値を渡すにはどうすればいいですか?テキストフィールドで値を追加する場合は、どうすれば保持できますか?テーブルセルにデータを渡す

- (void)viewDidLoad 
{  


tabledata = [[NSMutableArray alloc] initWithObjects:@"hello", nil]; 
tablesubtitles = [[NSMutableArray alloc] initWithObjects:@"hello", nil]; 
[super viewDidLoad]; 

//if I use "userdata.title" in replacemnent of @"hello" above, the table show up blank 



//self.navigationItem.rightBarButtonItem = self.editButtonItem; 

} 

//-------------------------------------- 

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

} 



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

UITableViewCell *cell = nil; 

cell = [tableView dequeueReusableCellWithIdentifier:@"homeworkcell"]; 

if(cell == nil) 
{ 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"homeworkcell"]; 

} 
cell.textLabel.text = [tabledata objectAtIndex:indexPath.row]; 
cell.detailTextLabel.text = [tablesubtitles objectAtIndex:indexPath.row]; 
cell.textLabel.font = [UIFont systemFontOfSize:14.0]; 

//static NSString *CellIdentifier = @"Cell"; 

/* if (cell == nil) { 
    cell = [[UITableViewCell alloc] 
      initWithStyle:UITableViewCellStyleSubtitle 
      reuseIdentifier:CellIdentifier]; 
}*/ 

// Configure the cell. 
//-----------------------------------------START----------------------------Set image of  cell---- 
cellImage = [UIImage imageNamed:@"checkboxblank.png"]; 

cell.imageView.image = cellImage; 

//--------------------------------------------END---------------------------end set image of cell-- 

return cell; 

} 
+0

userDataをこのクラスに渡す方法は? – beryllium

+0

#import "UserData.h"次にUserData * userdata; – user1191343

+0

これは通過ではなく、ヘッダーのインポートに過ぎません。作成する場所、テーブルのデータソースとしてinitとsetup? – beryllium

答えて

0

別のViewControllerを(例えばVC1)からデータを渡すために(VC2)は、プロパティそれ先のコントローラを設定することができます。だから、のUIViewController上記のために、あなたはビューコントローラのVC1に、

@property (nonatomic, retain) UserData *tableDatas; 

その後の.hに追加する必要があり、あなたが持っているでしょう:最後に

vc2.tableDatas = userdatas; 

を、UITableViewDelegate方法で:

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

あなただけ使用することができます。

cell.textLabel.text = [self.tableDatas objectAtIndex:indexPath.row]; 

調整が必要ですが、主要な部分はここにあります。

幸運。

関連する問題