Ios iPad中SplitViewController中的两个UITableView控制器,代理
嗨,这是我的第一个iPad应用程序,正在尝试将我的iphone应用程序移植到iPad。 我已经按照所有的教程从仍然有问题 同时回顾这个问题,仍然有问题 基本上,我在SplitViewController中有两个UITableViewController,当我单击根视图控制器中的tableview单元格时,我想在另一个tableview右侧的DetailsViewController中填充详细信息 问题是我可以设法从中传递数组数据,但我不能调用tableview重载方法Ios iPad中SplitViewController中的两个UITableView控制器,代理,ios,delegates,uitableview,tableview,uisplitviewcontroller,Ios,Delegates,Uitableview,Tableview,Uisplitviewcontroller,嗨,这是我的第一个iPad应用程序,正在尝试将我的iphone应用程序移植到iPad。 我已经按照所有的教程从仍然有问题 同时回顾这个问题,仍然有问题 基本上,我在SplitViewController中有两个UITableViewController,当我单击根视图控制器中的tableview单元格时,我想在另一个tableview右侧的DetailsViewController中填充详细信息 问题是我可以设法从中传递数组数据,但我不能调用tableview重载方法 这是密码 左视图控制器
这是密码 左视图控制器
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
if (row == 0){
NSLog(@"Row 0 Pressed");
RightViewController *rightvc = [self.storyboard instantiateViewControllerWithIdentifier:@"displayenglish"];
_locallayleft = [ConversationDatabase database].conversationsInfos;
NSLog(@"Just pushed the array");
rightvc.detailItem = _locallayleft;
rightvc.title = @"Greetings";
}
else if (row == 1) {
NSLog(@"Row 1 Pressed");
RightViewController *rightvc = [self.storyboard instantiateViewControllerWithIdentifier:@"displayenglish"];
_locallayleft = [ConversationDatabase database].conversationsInfosgeneral;
rightvc.detailItem = _locallayleft;
rightvc.title = @"General Conversation";
}
-----------------------------------------------------------------------------------------
RightViewController
- (void)setDetailItem:(NSArray *)newDetailItem
{
if(_detailItem != newDetailItem) {
_detailItem = newDetailItem;
[self configureView];
}
}
- (void)configureView
{
if (self.detailItem) {
self.locallay = self.detailItem;
_listOfCoversation = [[NSMutableArray alloc] init];
for (ConversationInEnglish *c in _locallay)
{
NSString *english = c.english;
NSLog(@"setDetails Item get called");
NSLog(@"%@",english);
[_listOfCoversation addObject:english];
}
[self.tableView reloadData];
NSLog(@"Trying to reload TableView");
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self configureView];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_locallay count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"English";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
ConversationInEnglish *con = _locallay [indexPath.row];
_englishLabel = (UILabel *) [cell viewWithTag:200];
_englishLabel.text = con.english;
NSLog(@"My data from cell %@",con.english );
[_englishLabel setFont:[UIFont fontWithName:@"Open Sans" size:22]];
_myanmarLabel = (UILabel *) [cell viewWithTag:300];
[_myanmarLabel setFont:[UIFont fontWithName:@"TharLon" size:17]];
_tonebasedLabel = (UILabel *) [cell viewWithTag:400];
_tonebasedLabel.text = con.tone_based;
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"tableviewcell.png"]];
self.tableView.backgroundColor = background;
return cell;
}
看起来,当您点击左边表格中的一行时,您不是在更新右边的表格,而是在从情节提要实例化一个全新的表格,而不是用它替换右边的表格 这里没有足够的上下文来确切说明如何修复它,但您要做的是,当您点击左侧表中的一行时,通过设置其detailItem属性来更新右侧表 您需要访问另一个表视图。有几种方法可以实现这一点,具体取决于您如何设置应用程序-如果您在iPhone和iPad上使用相同的左表视图,则可能需要一些条件代码来定位它,例如:
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
DetailViewController *detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
detailViewController.detailItem = newDetailItem;
}
或者,您可以通过故事板进行配置。无论哪种方式,关键都是查找和更新现有的表视图,而不是从情节提要中实例化一个新的表视图。您不需要以这种方式获取指向拆分视图控制器的指针,因为主控制器嵌入在拆分视图控制器中。只需使用self.splitViewController.Hey伙计们。非常感谢你。答案恰到好处。它起作用了。雅虎!谢谢@stevex和rdelmar。