0

IBにいくつかのViewControllerを設定しています。約6個のセル(プログラムで入力)を持つTableViewを持つもの。次に、さらに6つのビューコントローラー(各セルに1つ)。

私はそれを作りたいので

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

}

クリックしたセルに関連するビューにビューを切り替えることができます。

したがって、cell1をクリックすると、view1に移動し、cell2をクリックすると、view2に移動します。

これは私がちょうど私のテーブルを初期化する方法であり、それはうまく機能します。

//tableview datasource delegate methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return showArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *CellIdentifier = @"Cell";

CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];


if(cell == nil){
    cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.showLabel.text = [showArray objectAtIndex:indexPath.row];
cell.image.image = [UIImage imageNamed:[imageArray objectAtIndex:indexPath.row]];
cell.seasonLabel.text = [seasonArray objectAtIndex:indexPath.row];

return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 106;
}
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:    (UITableViewRowAnimation)animation{


NSIndexPath *newCellPath = [NSIndexPath indexPathForRow:showArray.count
                                              inSection:0];

[self.theatreView insertRowsAtIndexPaths:@[newCellPath]
                        withRowAnimation:UITableViewRowAnimationFade];

}

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

}
4

3 に答える 3

0

アプリの構造はわかりませんが、次のことを検討してください。

- (UIViewController *)getViewControllerAtIndexPath:(NSIndexPath *)indexPath {
    //..you can use "switch" to return the view controller you want
    return ...;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIViewController *controller = [self getViewControllerAtIndexPath:indexPath];
    //..push or present your controller
}
于 2012-10-30T04:00:35.050 に答える
0

アプリの構造に基づいて、これら2つの方法のいずれかをお勧めします。

[self.navigationController pushViewController:newViewController animated:YES];


[self presentModalViewController:newViewController animated:YES];

//for ios 6.0
[self presentViewController:newViewController animated:animated completion:NULL];

私が収集できるものから、メインメニューの.xibファイルに作成された多くのuiviewcontrollersがあります。あれは正しいですか?したがって、self.theatreViewControllerがあります。次に、それをボタンコールバックのパラメータとして渡すことができます。例えば

[self presentViewController:self.theatreViewController animated:animated completion:NULL];

ここでの私の仮定が間違っている場合は、私を訂正してください。

于 2012-10-29T23:54:03.557 に答える
0

このメソッドでインデックス パスプロパティを使用します: (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

お気に入り

yourObject = [yourArray objectAtIndex:indexPath];

編集: - 次のメソッドの AppDelegate で、これを行います:-

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{  

  self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.

  mHomeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
  UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mHomeViewController];
  [mHomeViewController release];

  self.window.rootViewController = navController;
  self.window.backgroundColor = [UIColor whiteColor];
  [self.window makeKeyAndVisible];
  [navController release];
  return YES;
}

ここで、viewController - didSelectRowMethod で、次のようにします。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString * object = [yourArray objectAtIndex:indexPath.row];

    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

    if(newControllerInstance == nil) // check if it's nil, then initialize and alloc it.
   {
      newControllerInstance = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
      [self.navigationController newControllerInstance animated:YES];
      [newControllerInstance release];
   }
}

これはうまくいくはずです。

于 2012-10-30T04:18:25.323 に答える