2009-11-10 28 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将新视图推送到堆栈。

希望这会有所帮助!