2017-10-25 3 views
-2

ユーザメッセージを表すUITableView内のセルのリストがあります。Object Cは、セルタップのデータを渡します。

セルをタップすると、メッセージの詳細ページに移動する必要があります。

メッセージIDをセルにリンクして、詳細ページに渡すにはどうすればよいですか?

+1

'のtableViewを与える'と呼ばれるべきです。次に、あなたは 'indexPath'を持っています。 tableViewに自分自身が移入されているので、使用している配列(配列を使用している場合)から 'id'を取得できます。その後、その「id」で詳細ページに行くことができます。 – Larme

答えて

1

テーブルビューセルをクリックまたはタップすると、テーブル表示セルデリゲートメソッド didSelectRowAtIndexPathメソッドが呼び出されます。その後、メッセージIDをdetailPageに渡すことができます。

私は配列を持っています。配列の内側に私はたくさんのIDを持っています。 didSelectRowAtIndexPath:

は私が例に、あなたに

ViewControlller.h

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource> 
@property (strong, nonatomic) NSMutableArray *arrSampData; 
@property (strong, nonatomic) IBOutlet UITableView *tblVwSample; 
@end 

ViewController.m

#import "ViewController.h" 
@interface ViewController(){ 
} 

@end 

@implementation ViewController 

@synthesize arrSampData; 
@synthesize tblVwSample; 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    arrSampData = [[NSMutableArray alloc]initWithObjects:@"55260",@"55261",@"55262",@"55263",@"55264",nil]; 
    } 

//UITableView Data Source methods 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [arrSampData count]; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *[email protected]"cell"; 
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellid]; 
    if (cell==nil) { 
     cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid]; 
    } 

    cell.textLabel.text=arrSampData[indexPath.row]; 
    return cell; 
} 

//UITableView Delegate methods 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *strID =[arrSampData objectAtIndex:indexPath.row]; 
    .......//Pass this id to your required view controller 
} 

@end 
0

cell.tagを使用してIDを保存する

+0

タグは文字列を格納できますか? –

+0

nope just integer – JJJ

0

問題を解決する方法がいくつかあります。それらのうちの1つは、テーブルビュー管理とカスタムセルのモデルを使用しています。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

他はセルタグを使用しています。詳細メッセージをセルタグに割り当ててから、

の方法で再度表示することができます。

または別のビューコントローラを使用して詳細を表示することができます。このためには、segueを実行し、ビューコントローラ間でデータを渡す必要があります。

関連する問題