Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 多个UITableViewController,在单个UITableView中具有多个UITablesViewCell_Objective C_Ipad_Uitableview_Ios5.1_Xcode4.6.3 - Fatal编程技术网

Objective c 多个UITableViewController,在单个UITableView中具有多个UITablesViewCell

Objective c 多个UITableViewController,在单个UITableView中具有多个UITablesViewCell,objective-c,ipad,uitableview,ios5.1,xcode4.6.3,Objective C,Ipad,Uitableview,Ios5.1,Xcode4.6.3,我正在iPad应用程序中进行列表显示 我有一个屏幕,屏幕上有一个UISegmentedController和一个UITableView UITableViewControllers都在一个类中定义,每个类都有自己的委托和数据源方法,用于访问和控制列表。有一个共享的超类,以及定义的两个超类 我以前在他们自己的屏幕中有列表,但我希望在单个屏幕中有列表,并使用选择器在视图之间切换 目前,我已设置代码在UITableViews之间切换,并尝试显示数据,并让代码以正确的方法调用正确的函数,但屏幕中的UIT

我正在iPad应用程序中进行列表显示

我有一个屏幕,屏幕上有一个
UISegmentedController
和一个
UITableView

UITableViewController
s都在一个类中定义,每个类都有自己的委托和数据源方法,用于访问和控制列表。有一个共享的超类,以及定义的两个超类

我以前在他们自己的屏幕中有列表,但我希望在单个屏幕中有列表,并使用选择器在视图之间切换

目前,我已设置代码在
UITableView
s之间切换,并尝试显示数据,并让代码以正确的方法调用正确的函数,但屏幕中的
UITableView
中未显示任何数据

我确信有一些“魔法”我并没有应用到这个问题上,但“咒语”并没有出现在我迄今为止发现的任何一个例子中

如何在现有TableView中的UITableViewController与其自己的UITableViewCell之间切换?


我试图在IOS 5.1中实现这一点,并使用Xcode 4.6.3作为开发环境。

您可以使用一个UITableView来显示所有数据。您可以使用UIButtons来代替使用UISegmentedControl。在UIButton的iAction中,您可以更改要显示的特定数据的dataArray。像

self.dataArray = array1;

[self.tableview reloadData];
并使用此dataArray在UITableView方法中显示数据

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    .....
}

你可以使用我在我的一个应用程序中使用的不同方法

#pragma mark - UITableView Delegate and DataSource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

        if (btnFavourites.selected) {
            return arrFavourites.count;
        }else if (btnHistory.selected){
            return arrHistories.count;
        }else if (btnHome.selected){
            return arrAddresses.count;
        }

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        static NSString *cellIdentifier = @"MyCell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }

        // Configure the cell...
        if (btnHome.selected) {
            Home *home = [arrAddresses objectAtIndex:indexPath.row];
            cell.textLabel.text = home.address;//[address valueForKey:@"address"];

        }else if (btnFavourites.selected){
            Favourites *favourite = [arrFavourites objectAtIndex:indexPath.row];
            cell.textLabel.text = favourite.location;//[favourite valueForKey:@"address"];

        }else if (btnHistory.selected){
            History *history = [arrHistories objectAtIndex:indexPath.row];
            cell.textLabel.text = history.location;// [history valueForKey:@"address"];

        }


        return cell;

}

您可以根据您的要求定制。希望这有帮助。谢谢。:)

以下是我用来“交换”UITableView的代码:

-(void)selectView:(NSInteger)selected
{
SectionListViewController *listViewController;

switch (selected) {
    default:
    case 0:  // Animal by Name
        listViewController = [[AnimalNameListViewController alloc] init];
        break;

    case 1:  // Animal by Breeder
        listViewController = [[AnimalBreederListViewController alloc] init];
        break;

    case 2:  // Animal by Owner
        listViewController = [[AnimalOwnerListViewController alloc] init];
        break;

    case 3:  // Animal by Breed
        listViewController = [[AnimalBreedListViewController alloc] init];
        break;

    case 4:  // Animal by RegOrg
        listViewController = [[AnimalRegOrgListViewController alloc] init];
        break;

    case 5:  // Breeder by Name
        listViewController = [[BreederNameListViewController alloc] init];
        break;
}

[listViewController initalizeTableListData];

[self.listView setDataSource:listViewController];
[self.listView setDelegate:listViewController];
self.listView = listViewController.tableView;

[listViewController.tableView reloadData];
}

它“几乎”起作用了。类中的委托和数据源例程被调用,但视图中没有数据

很接近,但“没有香蕉”。对于每个列表,我都有一个单独的类来完成字符串的全部工作,对于单元格样式,我有两个单独的TableViewCell方法,它们在情节提要中都是“自定义”的。代码如下:[listViewController initializeTableListData];[self.listView setDataSource:listViewController];[self.listView setDelegate:listViewController];self.listView=listViewController.tableView;[listViewController.tableView重新加载数据];我收到了对“委托”和“数据源”函数的调用,但显示的是一个空白列表,没有数据。listViewController是SectionListViewController类的对象,您正在使用其他类初始化(alloc init)。有可能吗?我从来没有做过这样的事。我不知道这是否可能。是否调用initializeTableListData方法?您可以使用调试指针来检查错误的位置和原因。好的,让我们从不同的角度来看这个问题。我有一个UIListViewController和一个UIListViewCell,我想在屏幕上的UIListView中显示它们。使用故事板进行此操作的“正确”方法是什么?耐心点。我对Objective C&IOS的了解大多来自互联网博客。UIListViewController???那是你的班名吗?它是从UITableViewController继承的吗?因此,您实际上要做的是创建一个UITableView并以编程方式显示内容。如果我是对的,请告诉我。我有一个名为SectionListViewController的超类,它基于UITableListViewController。我有两个子类AnimalListViewController(使用AnimalTableCell)和BrederListViewController(使用BrederTableCell)。每个子类都有子类。我在显示器中有一个UISegmentedControl来选择要显示的表,还有一个UITableView来显示它。那么,如何在“表”之间切换?是否需要将UITableListViewController放到UITableListView中?我头上的老茧是从砖墙上长出来的!您正在使用.xib作为UI,因此在选择特定段时必须使用nibName:alloc init。和要显示的控制器视图的设置框。试着用这个。希望这有帮助。