我是iPhone開發新手,我想在用戶點擊某一行時移動到另一個頁面。所以,如果他們點擊第一行,我希望頁面重定向到第一個視圖控制器,依此類推。每行都有自己的視圖控制器。當用戶點擊一行時,如何移動到另一個視圖控制器?
2
A
回答
0
0
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
switch (indexPath.row) {
case "X"
// Allocate the viewController
[navigationcontroller.pushViewController:"yourviewcontroller" animated:YES];
[release "yourviewcontroller"];
break;
default:
break;
}
}
編輯:沒有意識到你想什麼。正如shani所說,如果沒有必要,你不應該爲每一行創建一個viewcontroller。嘗試更改每行的數據源,但使用相同的viewcontroller。所以忘記這個實現。
3
首先,您不需要爲每一行設置不同的視圖控制器(除非您有足夠的理由這樣做)。
正確的方法是設置1個視圖控制器,該視圖控制器將適合原始數據中的所有單元格,並根據所選行更改其數據。
你做到這一點的方法是:
in the - DidSelectRowAtIndexPath function in your implementation file you shuld:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//allocate your view controller
DetailedViewController *detailedViewController = [[DetailedViewController alloc] init];
//send properties to your view controller
detailedViewController.property1 = someProperty1;
detailedViewController.property2 = someProperty2;
//push it to the navigationController
[[self navigationController] pushViewController:detailedViewController animated:YES];
[detailedViewController release];
}
我不建議您將使用蘋果的例子開始,他們是偉大的,有很多人:
祝你好運
0
簡單:
創建一個第二把你的視圖控制器在此委託功能:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
2
@kashyap在didSelectRowAtIndexPath
委託UITableView
你要檢查其上indexPath
你點擊的條件,並打開viewControllers
您已經相應地做出
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here -- for example, create and push another view controller.
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
switch (indexPath.row) {
case 0:
[self.navigationController pushViewController:firstViewController animated:YES];
[firstViewController release];
break;
case 1:
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController release];
break;
}//Likewise do for the no of rows you have in your `UITableView`
希望你明白我的意思.....祝你好運!
0
這聽起來像使用UINavigationController是你想要的。
然後您從表視圖把你的「第一個視圖」導航控制器的堆棧,例如,從您的UITableView委託:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
...
// indexPath.row == 0
FirstViewController* firstVC = [[FirstViewController alloc] initWithNibName...];
[self.navigationController firstVC animated:YES];
[firstVC release];
...
}
0
這是一個,我得到了問題,當我第一次的事情開始。這是我爲此使用的代碼。 在subviewcontroller我有我自己的構造像
-(id)initWithName:(NSString*)naMe
{
name=naMe;
return self;
}
而且在didSelectRowAtIndexPath
委託方法UITableView
。我ALLOC它
MyListView mylistview=[[MyListView alloc] initWithName:@"name"];
[self.navigationController pushViewController:mylistview animated:YES];
[mylistview release];
0
NSInteger row = indexPath.row;
UIViewController *newFrontController = nil;
if (row == 0)
{
YourViewController *yourViewController = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil];
newFrontController = [[UINavigationController alloc] initWithRootViewController:peopleViewController];
[self.navigationController setNavigationBarHidden:YES];
} else if(row == 1){
//do your code
}
中的tableView爲此在didSelectRowAtIndexPath方法。
相關問題
- 1. 如何移動到另一個視圖上點擊鼠標
- 2. 移動到另一個視圖控制器的正確方法
- 3. 加載一個外部視圖控制器,從一個按鈕點擊另一個視圖控制器
- 4. 按鈕點擊----從一個視圖移動到另一個視圖----?
- 5. 使從一個視圖控制器的圖像移動到另一個
- 6. 如何通過另一個視圖控制器啓動視圖控制器?
- 7. 如何將一個視圖移動到另一個視圖?
- 8. segue到另一個視圖控制器
- 9. 將視圖控制器從一個視圖控制器移動到另一個視圖控制器而無需導航控制器堆棧
- 10. 怎樣一個視圖控制器移動到另一個視圖 - 控制iOS中加載進度
- 11. 做一些按鈕點擊然後繼續到另一個視圖控制器
- 12. 當點擊行時,Angular UI Grid顯示另一個視圖
- 13. 如何從另一個控制1個視圖控制器?
- 14. 將視圖從一個視圖移動到另一個視圖
- 15. 移動到下一個視圖控制器,我用故事板
- 16. 從另一個視圖控制器通知視圖控制器
- 17. 如何發送圖像到另一個視圖控制器
- 18. 從一個視圖控制器到另一個視圖控制器進行委託調用
- 19. curlUp和curlDown從一個視圖控制器到另一個視圖的動畫
- 20. 當結果正確時加載另一個視圖控制器
- 21. 當另一個div被點擊時移動到下一個div的類
- 22. 如何從多個視圖控制器中的最後一個視圖控制器移動到第一個視圖控制器
- 23. 如何將根控制器移動到另一個控制器中
- 24. 如何在另一個視圖控制器中控制實例
- 25. 活動指示燈不啓動時的視圖控制器是導航到另一個視圖控制器
- 26. 如何從另一個視圖控制器呈現視圖控制器
- 27. iPhone如何將視圖控制器的視圖添加到另一個視圖控制器的視圖?
- 28. 如何將字符串值從一個視圖控制器傳遞到另一個視圖控制器
- 29. 如何通過按鈕從一個視圖控制器推到另一個視圖控制器?
- 30. 如何從一個表視圖控制器導航到另一個表視圖控制器在Xcode