gpt4 book ai didi

objective-c - 具有不同数组设置的 UITableView 多个部分

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:50:25 25 4
gpt4 key购买 nike

我想在 uitableview 中有 7 个不同行的部分,我不知道我应该如何编写不同的数组并将其设置在不同的部分中,我写了一个但每个部分中都有相同的数组!

你能帮帮我吗?

提前致谢!

我的意思是像下面的图片但是有不同的数组:例如我不想在每个部分进行测试和嘿

这是我的代码:

@synthesize monthTitle;

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super init];
if (self) {
monthTitle = [[NSMutableArray alloc] init];
}
return self;

}

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
[super viewDidLoad];
arry = [[NSMutableArray alloc] init];
[arry addObject:@"test"];
[arry addObject:@"hey"];



// 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.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self action:@selector(addNewItem)];
self.navigationItem.rightBarButtonItem = rightButton;
}

-(void)addNewItem{
[arry addObject:@"New Day"];
[self.tableView reloadData];
}
//- (IBAction)DeleteButtonAction:(id)sender
//
//{
//
// [arry removeLastObject];
//
// [self.tableView reloadData];
//
//}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 7;
//_week.days.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [arry count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self.tableView
dequeueReusableCellWithIdentifier:@"Cell"];


cell.textLabel.text = [arry objectAtIndex:indexPath.row];
return cell;

}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

if(section == 0)
return @"Monday";
else if(section == 1){
return @"Tuesday";
}else if(section == 2){
return @"Wednesday";
} else if(section == 3){
return @"Thuesday";
} else if(section == 4){
return @"Friday";
} else if(section == 5){
return @"Saturday";
}else
return @"Sunday";

}


// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}




- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[arry removeObjectAtIndex:indexPath.row];
//[self.monthTitle removeObjectAtIndex:indexPath.row];

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:
UITableViewRowAnimationFade];

// }else if (editingStyle==UITableViewCellEditingStyleInsert) {

}

//[self.tableView reloadData];

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib
name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}

@end

最佳答案

我认为以下文档中的 Array of Arrays 部分将指导您: http://briterideas.blogspot.com/2012/07/uitableview-how-to-part-3-multiple.html

关于objective-c - 具有不同数组设置的 UITableView 多个部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11689724/

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