2009-11-10 49 views
0

這裏是我在viewcontroller中使用我的appdelegate中提供的plist信息的代碼。用plist填充表格推送不同的視圖控制器

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 


// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [self.tableDataSource count]; 
} 


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

    static NSString *CellIdentifier = @"Cell"; 

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


    NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row]; 
    cell.text = [dictionary objectForKey:@"myobject"]; 

這使用了在appdelegate中使用的plist,並在我的表格中填充了我的plist中有多少個入口。

我想要做的下一件事是爲每個填充了相應「鍵」的單元格推送一個非動態viewcontoller。

所以,myobject單元格(選中時)將推動myobject viewcontroller。 yourobject單元格(選中時)將按下對象視圖控制器。

All the way down. 

我該怎麼去做這件事?

回答

1
  1. 您的主窗口是否包含UINavigationController,並將上述表視圖設置爲根視圖控制器。
  2. 讓您的表視圖包含您的輔助視圖控制器的成員變量,它將成爲該項目的「詳細視圖」。初始化它(例如viewDidLoad)。
  3. 讓您的詳細信息視圖包含要顯示的信息(即字典中的元素)的成員變量。我們稱之爲myData。
  4. 在您的表視圖中實現didSelectRowAtIndexPath以檢測何時選中某行。在這裏,您將根據選定的行從字典中查找對象,將其設置爲詳細控制器上的myData,並在導航控制器上使用pushViewController將新視圖推送到堆棧。

希望這會有所幫助!

相關問題