开发者

Can you programmatically change the style of a UITableView after it's been created? [duplicate]

开发者 https://www.devze.com 2023-03-04 14:43 出处:网络
This question already has answers here: How can I set a UITableView to grouped style (18 answers) Closed 8 years ago.
This question already has answers here: How can I set a UITableView to grouped style (18 answers) Closed 8 years ago.

(This is about programatically swapping the style of existing tableview and not about setting table view style programatically)

I have a situation where I used a grouped table view in a view this table is editable and whenever it goes to editable view it gets displaced so what I thought was to change its style to plain whenever it goes to editing mode.

Is this possible? (Thanks in advance.)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *MyIdentifier = @"MyIdentifier";
MyIdentifier = [NSString stringWithFormat:@"Cell %d",indexPath.row];


 // MyIdentifier =@"tblCellView";
    NSString *offendersImagePath = [self applicationDocumentsDirectory];
    //NSLog(@"%@", db开发者_高级运维Path);
    offendersImagePath=[offendersImagePath stringByAppendingPathComponent:@"Images"];


CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
    cell = aCustomCell;
    aCustomCell=nil;
}


No this is not possible See this is wriiten in apple documentation:-

You set the table style when you initialize the table view (see initWithFrame:style:). You cannot modify the style thereafter.

So you can not modify it afterwards...


I dont think you can change the style of UITableView dynamically and set to plain or grouped. I think you have to do that while initializing it

-(id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style


Another possible solution would be to have multiple UITableViewCell prototypes and switch them whenever necessary.

0

精彩评论

暂无评论...
验证码 换一张
取 消