Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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
Ios 如何在switch部分用自定义类实例化UITableViewCell_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 如何在switch部分用自定义类实例化UITableViewCell

Ios 如何在switch部分用自定义类实例化UITableViewCell,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我需要在cellForRowAtIndexPath的开头创建一个对象,以便使用switch部分在其中添加不同的单元格: switch (indexPath.section) { case DetailControllerAddressSection: { NSString *address = [self addressText]; UITableViewCell *cell; if (UI_USER_INTERFACE_IDIOM() =

我需要在
cellForRowAtIndexPath
的开头创建一个对象,以便使用switch部分在其中添加不同的单元格:

switch (indexPath.section) {
    case DetailControllerAddressSection: {
        NSString *address = [self addressText];
        UITableViewCell *cell;
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            if (IS_OS_7_OR_LATER) {
                cell = (CustomDetailCell *) [tableView dequeueReusableCellWithIdentifier:@"AddressCell" forIndexPath:indexPath];
                cell.mainLabel.text = address;
                cell.detailLabel.text = [self distanceMessageForObjectData:self.objectData];
            } else {
                UniversalAddressCell *cell = (UniversalAddressCell *) [tableView dequeueReusableCellWithIdentifier:@"UniversalAddressCell" forIndexPath:indexPath];
                cell.backgroundView = [self cellBackgroundImageView:indexPath];
                cell.mainLabel.text = address;
...

但是在本例中,单元格是
UITableViewCell
,我无法从
CustomDetailCell
类中获取标签。如何解决这个问题?我相信这个决定很简单,但我不知道如何解决它。

我想你应该做打字

[(CustomDetailCell *)cell mainLabel].text = address;

我猜你会做打字

[(CustomDetailCell *)cell mainLabel].text = address;

我猜你会做打字

[(CustomDetailCell *)cell mainLabel].text = address;

我猜你会做打字

[(CustomDetailCell *)cell mainLabel].text = address;

问题在于:
UITableViewCell*单元格

即使将单元格强制转换为
(CustomDetailCell*)
存储类型仍然是
UITableViewCell

你能做的是:

switch (indexPath.section) {
case DetailControllerAddressSection: {
    NSString *address = [self addressText];
    UITableViewCell *cell;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        if (IS_OS_7_OR_LATER) {
            CustomDetailCell *detailCell = (CustomDetailCell *) [tableView dequeueReusableCellWithIdentifier:@"AddressCell" forIndexPath:indexPath];
            detailCell.mainLabel.text = address;
            detailCell.detailLabel.text = [self distanceMessageForObjectData:self.objectData];
            cell = detailCell;

        } else {
            UniversalAddressCell *universalCell = (UniversalAddressCell *) [tableView dequeueReusableCellWithIdentifier:@"UniversalAddressCell" forIndexPath:indexPath];
            universalCell.backgroundView = [self cellBackgroundImageView:indexPath];
            universalCell.mainLabel.text = address;
            cell = universalCell;

问题在于:
UITableViewCell*单元格

即使将单元格强制转换为
(CustomDetailCell*)
存储类型仍然是
UITableViewCell

你能做的是:

switch (indexPath.section) {
case DetailControllerAddressSection: {
    NSString *address = [self addressText];
    UITableViewCell *cell;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        if (IS_OS_7_OR_LATER) {
            CustomDetailCell *detailCell = (CustomDetailCell *) [tableView dequeueReusableCellWithIdentifier:@"AddressCell" forIndexPath:indexPath];
            detailCell.mainLabel.text = address;
            detailCell.detailLabel.text = [self distanceMessageForObjectData:self.objectData];
            cell = detailCell;

        } else {
            UniversalAddressCell *universalCell = (UniversalAddressCell *) [tableView dequeueReusableCellWithIdentifier:@"UniversalAddressCell" forIndexPath:indexPath];
            universalCell.backgroundView = [self cellBackgroundImageView:indexPath];
            universalCell.mainLabel.text = address;
            cell = universalCell;

问题在于:
UITableViewCell*单元格

即使将单元格强制转换为
(CustomDetailCell*)
存储类型仍然是
UITableViewCell

你能做的是:

switch (indexPath.section) {
case DetailControllerAddressSection: {
    NSString *address = [self addressText];
    UITableViewCell *cell;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        if (IS_OS_7_OR_LATER) {
            CustomDetailCell *detailCell = (CustomDetailCell *) [tableView dequeueReusableCellWithIdentifier:@"AddressCell" forIndexPath:indexPath];
            detailCell.mainLabel.text = address;
            detailCell.detailLabel.text = [self distanceMessageForObjectData:self.objectData];
            cell = detailCell;

        } else {
            UniversalAddressCell *universalCell = (UniversalAddressCell *) [tableView dequeueReusableCellWithIdentifier:@"UniversalAddressCell" forIndexPath:indexPath];
            universalCell.backgroundView = [self cellBackgroundImageView:indexPath];
            universalCell.mainLabel.text = address;
            cell = universalCell;

问题在于:
UITableViewCell*单元格

即使将单元格强制转换为
(CustomDetailCell*)
存储类型仍然是
UITableViewCell

你能做的是:

switch (indexPath.section) {
case DetailControllerAddressSection: {
    NSString *address = [self addressText];
    UITableViewCell *cell;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        if (IS_OS_7_OR_LATER) {
            CustomDetailCell *detailCell = (CustomDetailCell *) [tableView dequeueReusableCellWithIdentifier:@"AddressCell" forIndexPath:indexPath];
            detailCell.mainLabel.text = address;
            detailCell.detailLabel.text = [self distanceMessageForObjectData:self.objectData];
            cell = detailCell;

        } else {
            UniversalAddressCell *universalCell = (UniversalAddressCell *) [tableView dequeueReusableCellWithIdentifier:@"UniversalAddressCell" forIndexPath:indexPath];
            universalCell.backgroundView = [self cellBackgroundImageView:indexPath];
            universalCell.mainLabel.text = address;
            cell = universalCell;

如果两个单元格有两个不同的笔尖:

静态NSString*simpleTableIdentifier=@“SimpleTableCell”


如果两个单元格有两个不同的笔尖:

静态NSString*simpleTableIdentifier=@“SimpleTableCell”


如果两个单元格有两个不同的笔尖:

静态NSString*simpleTableIdentifier=@“SimpleTableCell”


如果两个单元格有两个不同的笔尖:

静态NSString*simpleTableIdentifier=@“SimpleTableCell”