Note that there are some explanatory texts on larger screens.

plurals
  1. POText in uitableviewcell aligned unequally?
    primarykey
    data
    text
    <p>Here is how my <code>UItableView</code> looks like:</p> <p><img src="https://i.stack.imgur.com/rTcEH.png" alt="enter image description here"></p> <p>The last cell, <strong>Coke</strong> is not aligned properly as the other cells. How can I fix this?</p> <p>Here is all my code:</p> <pre><code>#import "SearchViewController.h" @interface SearchViewController () { NSMutableArray *filteredStrings; NSMutableArray *arrayDataFromServer; NSMutableArray *totalStrings; BOOL isFiltered; } @end @implementation SearchViewController - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.SearchBar.delegate = self; self.tableView.delegate = self; self.tableView.dataSource = self; NSString *strURL = [NSString stringWithFormat:@"http://localhost:8888/Search.php?choice=name"]; NSArray *arrayImagesNames = [[NSMutableArray alloc] initWithContentsOfURL:[NSURL URLWithString:strURL]]; arrayDataFromServer = [[NSMutableArray alloc]init]; NSEnumerator *enumForNames = [arrayImagesNames objectEnumerator]; id objName; while ( objName = [enumForNames nextObject]) { [arrayDataFromServer addObject:[NSDictionary dictionaryWithObjectsAndKeys:objName, @"name", nil]]; } } -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { NSString *strURL = [NSString stringWithFormat:@"http://localhost:8888/Search.php?choice=name"]; NSArray *arrayImagesNames = [[NSMutableArray alloc] initWithContentsOfURL:[NSURL URLWithString:strURL]]; NSLog(@"%@", arrayImagesNames); if (searchText.length == 0) { isFiltered = NO; } else { isFiltered = YES; filteredStrings = [[NSMutableArray alloc]init]; for (NSString *str in arrayImagesNames) { NSRange stringRange = [str rangeOfString:searchText options:NSCaseInsensitiveSearch]; if (stringRange.location != NSNotFound) { [filteredStrings addObject:str]; } } } [self.tableView reloadData]; } -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { [self.SearchBar resignFirstResponder]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { //#warning Potentially incomplete method implementation. // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { //#warning Incomplete method implementation. // Return the number of rows in the section. if (isFiltered) { return [filteredStrings count]; } return [arrayDataFromServer count]; } - (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 (!isFiltered) { NSString *nn = [[arrayDataFromServer objectAtIndex:indexPath.row] objectForKey:@"name"]; cell.textLabel.text = nn; } else { cell.textLabel.text = [filteredStrings objectAtIndex:indexPath.row]; } [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; return cell; } </code></pre> <p>I used the SearchBar to search the cells. All the information in the cells are called from the server. I have tried to used the normal array <code>..@"1", @"2", @"3"...,nil];</code> and the text aligned properly.</p> <p>Any help would be very much appreciated! Thanks in advance!</p> <p>I used NSLog to display the array:</p> <p><img src="https://i.stack.imgur.com/H0DPx.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload