Próbuję zaimplementować aplikację opartą na UITableView. Aby wybrać UITableViewStyle jest Group.In moim TableView ich jest sekcji każdej sekcji posiadającej 1 wiersz.Dlaczego sprawdzamy, czy (komórka == zero) w UITableViewController?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 15;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section==12)
{
return 120;
}
else
{
return 60;
}
}
Chcę dodać UITextView w sekcji
Do tego zrobiłem następujący kod
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if ([indexPath section] == 12)
{
if([indexPath row]==0)
{
descriptionTextField=[[UITextView alloc] initWithFrame:CGRectMake(5, 8, 290, 106)];
descriptionTextField.font = [UIFont systemFontOfSize:15.0];
descriptionTextField.backgroundColor=[UIColor scrollViewTexturedBackgroundColor];
[descriptionTextField setDelegate:self];
[descriptionTextField setTag:2];
[descriptionTextField setText:@"Enter Location Description."];
descriptionTextField.keyboardType=UIKeyboardTypeDefault;
descriptionTextField.returnKeyType=UIReturnKeyNext;
descriptionTextField.textColor=[UIColor blackColor];
descriptionTextField.editable=YES;
descriptionTextField.autocapitalizationType=UITextAutocapitalizationTypeWords;
descriptionTextField.autocorrectionType=UITextAutocorrectionTypeDefault;
descriptionTextField.textAlignment=UITextAlignmentLeft;
UIToolbar* keboardToolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 32)];
UIBarButtonItem *extra=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *Done=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(keyboardDoneButtonActin:)];
[Done setWidth:65.0f];
[keboardToolBar setItems:[[[NSArray alloc]initWithObjects:extra,Done, nil]autorelease] ];
[extra release];
[Done release];
[keboardToolBar setTintColor:[UIColor blackColor]];
[keboardToolBar setAlpha:.70];
[descriptionTextField setInputAccessoryView:keboardToolBar];
[descriptionTextField setTag:101];
[cell.contentView addSubview:descriptionTextField];
[descriptionTextField release];
}
}
return cell;
}
W initil etapie widok tabeli jak ten
jeśli przewijam widok tabeli w górę iw dół, to zmieniono sekcję uitextView i wyświetlono wiele lokalizacji.
Nie mogę zrozumieć, moja wina, dlaczego tak się stało?
jeśli jestem wykonawczych powyższy kod na stronie if (komórka == nil)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
if ([indexPath section] == 12)
{
if([indexPath row]==0)
{
**/* implemention all code here*/**
[cell.contentView addSubview:descriptionTextField];
[descriptionTextField release];
}
}
return cell;
}
UITextView nie disply, myślę, że nie jest przydzielenie.
więc co stanowi różnicę pomiędzy kodu wykonawczego jeśli (komórka == ml) { wewnątrz }
jeśli (komórka == ml) { } z boku
różnica polega na tym, że kiedy napisałeś kod w komórce == zero, będzie działać tylko raz na początku, jeśli napiszesz, to stworzy za każdym razem, gdy obciążenie widoku –
powodowało zmianę wartości przekroju podczas przewijania widoku tabeli. czy mogę napisać kod na bok? –
jeszcze jedna rzecz, którą możesz zrobić w swoim kodzie, ustaw jedną wartość tagu dla widoku tekstowego, a następnie napisz ten kod [[cell.contentView viewWithTag: 100 + indexPath.row] removeFromSuperview]; 100 + index.row jest wartością zmiennej –