gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:43:51 24 4
gpt4 key购买 nike

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 重新加载方法。


这是代码

左 View Controller

- (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;
}

最佳答案

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

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

您需要访问其他 TableView 。根据您设置应用程序的方式,有几种方法可以做到这一点——如果您在 iPhone 和 iPad 上使用相同的左 TableView ,那么您可能需要一些条件代码来定位它,例如示例:

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

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

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com