=>わかっています、これはばかげた質問ですが、これは私のように新しい iPhone 開発者にとってより重要です。
ここで、 UITableViewセクションに関連する質問があります:
最初の問題:複数のセクションから番号 0 で UITableView セクションを開始するにはどうすればよいかという質問があります。
例えば :
私はデリゲートメソッドで11のセクション番号を持っていますUITableView
.numberOfSectionsInTableView
私のセクションは最初にセクションの11番目の番号で始まり、次に0,1,2,3,4,5,6,7,8,9と10です。私のセクション番号は0番号で、そのままです。
2番目の問題:デリゲートメソッドでtitleForHeaderInSection
は、tableViewのすべてのセクションが3回繰り返されます。現在のViewControllerで、UITableViewを上下にスクロールし、セクションを通常(0〜11)として表示します。セクションを3回繰り返した後、UITableViewのこの通常のセクションが表示されます。
例えば :
私はデリゲートメソッドで使用NSLog (@" %d ", section );
し titleForHeaderInSection
、以下のようにコンソールに出力を表示します
コンソール出力:
2012-09-17 12:27:47.424 Quotes2You[1623:f803] 11
2012-09-17 12:27:47.426 Quotes2You[1623:f803] 11
2012-09-17 12:27:47.427 Quotes2You[1623:f803] 11
2012-09-17 12:27:47.428 Quotes2You[1623:f803] 0
2012-09-17 12:27:47.429 Quotes2You[1623:f803] 0
2012-09-17 12:27:47.429 Quotes2You[1623:f803] 0
2012-09-17 12:27:47.430 Quotes2You[1623:f803] 1
2012-09-17 12:27:47.431 Quotes2You[1623:f803] 1
2012-09-17 12:27:47.431 Quotes2You[1623:f803] 1
2012-09-17 12:27:47.432 Quotes2You[1623:f803] 2
2012-09-17 12:27:47.433 Quotes2You[1623:f803] 2
2012-09-17 12:27:47.433 Quotes2You[1623:f803] 2
2012-09-17 12:27:47.434 Quotes2You[1623:f803] 3
2012-09-17 12:27:47.435 Quotes2You[1623:f803] 3
2012-09-17 12:27:47.436 Quotes2You[1623:f803] 3
2012-09-17 12:27:47.436 Quotes2You[1623:f803] 4
2012-09-17 12:27:47.437 Quotes2You[1623:f803] 4
2012-09-17 12:27:47.438 Quotes2You[1623:f803] 4
2012-09-17 12:27:47.438 Quotes2You[1623:f803] 5
2012-09-17 12:27:47.439 Quotes2You[1623:f803] 5
2012-09-17 12:27:47.439 Quotes2You[1623:f803] 5
2012-09-17 12:27:47.440 Quotes2You[1623:f803] 6
2012-09-17 12:27:47.441 Quotes2You[1623:f803] 6
2012-09-17 12:27:47.462 Quotes2You[1623:f803] 6
2012-09-17 12:27:47.463 Quotes2You[1623:f803] 7
2012-09-17 12:27:47.464 Quotes2You[1623:f803] 7
2012-09-17 12:27:47.465 Quotes2You[1623:f803] 7
2012-09-17 12:27:47.466 Quotes2You[1623:f803] 8
2012-09-17 12:27:47.466 Quotes2You[1623:f803] 8
2012-09-17 12:27:47.467 Quotes2You[1623:f803] 8
2012-09-17 12:27:47.472 Quotes2You[1623:f803] 9
2012-09-17 12:27:47.476 Quotes2You[1623:f803] 9
2012-09-17 12:27:47.478 Quotes2You[1623:f803] 9
2012-09-17 12:27:47.480 Quotes2You[1623:f803] 10
2012-09-17 12:27:47.481 Quotes2You[1623:f803] 10
2012-09-17 12:27:47.481 Quotes2You[1623:f803] 10
2012-09-17 12:27:47.487 Quotes2You[1623:f803] 0
2012-09-17 12:27:47.487 Quotes2You[1623:f803] 1
2012-09-17 12:27:47.489 Quotes2You[1623:f803] 2
最初にすべてのセクションを 3 回繰り返し、UITableView をスクロールした後、セクションを 0 から開始します (通常どおり)。
私のコードはここにあります:
ThirdViewController.h
@interface ThirdViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
{
UITableView *tblCustomer;
NSArray *listOfsection;
}
@property (nonatomic,retain) UITableView *tblCustomer;
@property (nonatomic,retain) NSArray *listOfsection;
@end
ThirdViewController.m
@synthesize tblCustomer , listOfsection;
- (void)viewDidLoad
{
[super viewDidLoad];
self.tblCustomer = [[UITableView alloc] initWithFrame:CGRectMake(0,0,320,417) style:UITableViewStyleGrouped];
self.tblCustomer.delegate = self;
self.tblCustomer.dataSource = self;
[self.view addSubview:self.tblCustomer];
self.listOfsection = [[NSArray alloc] initWithObjects:@"Name", @"Company", @"Address", @"Email", @"Mobile", @"Phone", @"Potential", @"Sales Status", @"Genre", @"Distributor", @"Dist Rep", @"Internal Notes", nil];
}
#pragma mark - UITableView Datasource Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView {
return [self.listOfsection count];
}
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
int numSection=0;
if (section == 2)
numSection = 5;
else
numSection = 1;
return numSection;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// here is my code cellForRowAtIndexPath as section wise
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSLog(@" %d ", section);
NSString *sectionHeader = nil;
sectionHeader = [self.listOfsection objectAtIndex:section];
// here is section overwrite //
return sectionHeader;
}
#pragma mark - Memory Management
-(void)dealloc
{
[super dealloc];
[self.listOfsection release];
[self.tblCustomer release];
}
前もって感謝します