• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - iPad 中 SplitViewController 中的两个 UITableView Controller ,Delegate

[复制链接]
菜鸟教程小白 发表于 2022-12-12 10:04:03 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

enter image description here

嗨,这是我的第一个 iPad 应用程序,正在尝试将我的 iphone 应用程序移植到 iPad。 我已按照 http://www.raywenderlich.com/ 中的所有教程进行操作仍然有问题。

还要查看这个问题,但问题仍然存在。 Splitviewcontroller with two tableviews, delegate problem

基本上,我在 SplitViewController 中有两个 UITableViewController,当我单击 Root View Controller 中的 tableview 单元格时,我想在另一个 Tableview 右侧的 DetailsViewController 中填充详细信息。

问题是我可以设法从中传递数组数据,但我不能调用 tableview reload 方法。


这里是代码

左 View Controller

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)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)setDetailItemNSArray *)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)numberOfSectionsInTableViewUITableView *)tableView
{

    return 1;
}

- (NSInteger)tableViewUITableView *)tableView numberOfRowsInSectionNSInteger)section
{

    return [_locallay count];

}

- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)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;
}



Best Answer-推荐答案


看起来当您点击左侧表格中的一行时,不是更新右侧的表格,而是从 Storyboard 中实例化一个全新的表格,而不是用它替换右侧的表格.

这里没有足够的上下文来准确说明如何修复它,但是您想要做的是当您点击左侧表格中的一行时,通过设置其 detailItem 属性来更新右侧表格.

您需要访问其他表格 View 。有几种方法可以做到这一点,具体取决于您如何设置应用程序 - 如果您在 iPhone 和 iPad 上使用相同的左 TableView ,那么您可能需要一些条件代码来定位它,因为示例:

if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
    DetailViewController *detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
    detailViewController.detailItem = newDetailItem;
}

或者您可以通过 Storyboard 对其进行配置。无论哪种方式,关键是找到并更新现有的 TableView ,而不是从 Storyboard 中实例化一个新的。

关于ios - iPad 中 SplitViewController 中的两个 UITableView Controller ,Delegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15848328/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap