Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.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 无法在不影响动画的情况下调用DidSelectRowatineXpath中的CellForRowatineXpath?_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 无法在不影响动画的情况下调用DidSelectRowatineXpath中的CellForRowatineXpath?

Ios 无法在不影响动画的情况下调用DidSelectRowatineXpath中的CellForRowatineXpath?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我检查了所有重复的问题。但我没有找到解决这个问题的办法。如果我的问题不恰当,请纠正我 我有一个带有标签(用于标题)和文本视图(用于说明)的自定义单元格。我在试可膨胀电池。首先,它将只显示标题,当我点击时,它将显示描述。因此,在开始时,文本视图(说明)将被隐藏(我将在cellforrowatinexpath中指定),每当用户触摸单元格时,我将在didselectrowatinexpath功能中检测到该单元格,并将更改高度 我知道我可以使用[tableView reload]函数调用cellforr

我检查了所有重复的问题。但我没有找到解决这个问题的办法。如果我的问题不恰当,请纠正我

我有一个带有标签(用于标题)和文本视图(用于说明)的自定义单元格。我在试可膨胀电池。首先,它将只显示标题,当我点击时,它将显示描述。因此,在开始时,文本视图(说明)将被隐藏(我将在
cellforrowatinexpath
中指定),每当用户触摸单元格时,我将在
didselectrowatinexpath
功能中检测到该单元格,并将更改高度

我知道我可以使用
[tableView reload]
函数调用
cellforrowatinexpath
。但我用的是

[tableView beginUpdates];
[tableView endUpdates];
内选择rowatindexpath
以在高度变化时播放动画。在这里,如果我使用
[tableView reload]
,动画将无法工作。数据显示完美,但没有动画

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView beginUpdates];
    if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
        self.expandedIndexPath = nil;
    } else {
        self.expandedIndexPath = indexPath;
    }
  [tableView endUpdates];
}
我希望在
didSelectRowAtIndexPath
内调用
cellForRowAtIndexPath
函数,而不影响动画

谢谢你的时间(:

我的代码:

#import "MyListViewController.h"
#import "CustomCell.h"

@interface MyListViewController ()
@property NSArray* tableData;
@property (strong, nonatomic) NSIndexPath *expandedIndexPath;
@end

@implementation MyListViewController

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.tableData count];
}

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

    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.secondary.text = @"adfasdfasdfsdfsdffassssssddalfdsaldjsfadsfasdfdjsfldsjfakldsfjlasfaksfjadksfaldfjladksfjadksfjdkslsdjjlkflasfaljfajfalkflkadslsdfljksdfajsdasdfjlkafsjlkasdjfafsdjadfjksadjsladfjsajladfjslas";
    if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
        cell.primaryLabel.text = [self.tableData objectAtIndex:indexPath.row];
        cell.secondary.hidden = NO;

    }else{
        cell.primaryLabel.text = [self.tableData objectAtIndex:indexPath.row];
        cell.secondary.hidden = YES;
    }
       // cell.textLabel.text = [self.tableData objectAtIndex:indexPath.row];
   // cell.imageView.image = [UIImage imageNamed:@"creme_brelee.jpg"];
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    //[tableView reloadData];
    if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {

        return 100.0; // Expanded height

    }
    return 30.0; // Normal height
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView beginUpdates];
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
        self.expandedIndexPath = nil;
    } else {
        self.expandedIndexPath = indexPath;
    }
  [tableView endUpdates];
}



- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableView.delegate=self;
    self.tableView.dataSource=self;

    self.tableData = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee", @"Vegetable Curry", @"Instant Noodle with Egg", @"Noodle with BBQ Pork", @"Japanese Noodle with Pork", @"Green Tea", @"Thai Shrimp Cake", @"Angry Birds Cake", @"Ham and Cheese Panini", nil];


    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 1;
 }




@end

您应该这样做,并根据需要更改动画

[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:@[self.expandedIndexPath] withRowAnimation:UITableViewRowAnimationBottom];
[tableView endUpdates]; 

是否尝试重新加载特定行。动画同时适用于标题和说明。我只想为说明(tableView)设置动画我不明白这是如何工作的……当我使用
UITableViewRowAnimationBottom
而不是
UITableViewRowAnimationAutomatic
时,它为标题和描述设置动画。但我不知道
UITableViewRowAnimationAutomatic
如何完美工作。它只是为描述单独设置动画,即使它是加载整行。您能解释一下吗?UITableViewRowAnimationAutomatic的目的是让表视图自动选择一个看起来不错的动画。例如,当在节的开头插入行时,表视图将使用UITableViewRowAnimationBottom。当在节的结尾插入行时,表视图将使用UITableViewRowAnimationBottom表视图将使用UITableViewRowAnimationTop。在这里,您没有添加任何新行,因此UITableViewRowAnimationBottom不正确。这会产生另一个问题。它只影响当前行,但我希望关闭以前扩展的行。因此,我需要调用
cellForRowAtIndexPath
而不仅仅是当前行。您没有提到过这一点在问题“我想关闭以前扩展的行”中。
[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationAutomatic];//indexpath of your selected row
[tableView endUpdates];