2010-05-06 67 views
0

我想學習如何使用不同的視圖,對於這個示例測試應用程序,我有一個登錄頁面,成功登錄後,用戶重定向到表視圖,然後選擇在表格視圖中的項目中,用戶被引導到顯示項目細節的第三頁面。Iphone SDK - 將UITableView添加到UIView

第一頁工作得很好,但是當我進入第二頁時,問題發生,所顯示的表沒有標題,我無法添加標題或工具欄或除表格本身內容以外的任何內容。當我點擊該項目時,不用說沒有任何反應。沒有錯誤。

我對編程相當陌生,一直在Java上工作,但從來沒有在C上(雖然我有一些C的基本知識),Objective C對我來說是新的。

這是代碼。

-(IBAction) login { 

RootViewController *rootViewController = [[RootViewController alloc] init]; 

if([username.text isEqualToString:@"test"]&&[password.text isEqualToString:@"test"]){ 
[window addSubview:[rootViewController view]]; 

[window makeKeyAndVisible]; 
} 

else { 
    loginError.text = @"LOGIN ERROR"; 
    [window addSubview:[viewController view]]; 
    [window makeKeyAndVisible]; 
} 
} 

@interface RootViewController : UITableViewController { 

IBOutlet NSMutableArray *views; 
} 

@property (nonatomic, retain) IBOutlet NSMutableArray * views; 

- (void)viewDidLoad { 

views = [ [NSMutableArray alloc] init]; 

OpportunityOne *opportunityOneController; 

for (int i=1; i<=20; i++) { 
    opportunityOneController = [[OpportunityOne alloc] init]; 
    opportunityOneController.title = [[NSString alloc] initWithFormat:@"Opportunity %i",i]; 

    [views addObject:[NSDictionary dictionaryWithObjectsAndKeys: 
         [[NSString alloc] initWithFormat:@"Opportunity %i",i], @ "title",      opportunityOneController, @"controller",      nil]]; 
    [email protected]"GPS"; 
} 

[super viewDidLoad]; 

} 

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

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Configure the cell. 

cell.textLabel.text = [[views objectAtIndex:indexPath.row] objectForKey:@"title"]; 

return cell; 
} 


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

UIViewController *targetViewController = [[views objectAtIndex:indexPath.row] objectForKey:@"controller"]; 

[[self navigationController] pushViewController:targetViewController animated:YES]; 

} 

哇,我發現真的很難發佈代碼。我爲壞的格式道歉,但我無法超越這個文本編輯器的格式化規則。

感謝, 沙市

+0

這是太多的代碼讓人們看,更不用說重新格式化了。通過更簡單的教程,學習縮小問題範圍,只顯示相關的代碼。如果信息不夠,人們會要求更多。 – DyingCactus 2010-05-07 02:05:35

+0

我想我已經刪除了很多不必要的代碼,讓我知道如果我需要清理更多。 – Shashi 2010-05-07 05:15:52

回答

0

開始導航基礎的應用。根據需要製作儘可能多的視圖控制器(從上面3個)。根據需要將視圖控制器從一個推到另一個。

+0

我想學習使用基於窗口的應用程序,我可以添加任何數量的簡單按鈕的簡單意見,沒有問題,但只有當我想創建一個UIView-> UITableView-> UIView我有問題。在第二個視圖中,我所看到的只是表格,沒有標題,沒有任何工具欄。我可以創建一個基於導航的應用程序,我有一個UITableView - > UIView,它工作得很好。 – Shashi 2010-05-07 19:39:23