Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView does not show data in NSMutableArray
    text
    copied!<p>please help me with this problem. I cannot find any problem for the last 4 days and nights. This is the simple job that I already did in another project. But the different thing is that this is my first time to use UISearchBar with Display Controller. Anyway here are my codes.</p> <p>mnuSearch.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "constants.h" #import "JSON.h" #import "Initial.h" @interface mnuSearch : UIViewController&lt;UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate&gt; { } @property (retain) NSMutableArray *_arrSearchNews; @property (nonatomic, retain) IBOutlet UISearchBar *txtSearchBox; @property (nonatomic, retain) IBOutlet UITableView *tblNewsSearch; @end </code></pre> <p>mnuSearch.m</p> <pre><code>#import "mnuSearch.h" @interface mnuSearch () @end @implementation mnuSearch @synthesize _arrSearchNews; @synthesize txtSearchBox, tblNewsSearch; #pragma mark - When "search button" in keyboard is clicked - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { [searchBar setShowsCancelButton:NO animated:YES]; [searchBar resignFirstResponder]; [self searchNews:searchBar.text]; [self.tblNewsSearch reloadData]; } #pragma mark - Search news -(void)searchNews:(NSString*)query { // Retrieve searched news list NSString *url = [NSString stringWithFormat:@"http://mydomain.com/NewsSearch.ashx?a=%@&amp;b=%@&amp;c=%@", currentLocale, uniqueID, [Initial getUrlEncode:query]]; NSURLRequest *_rqJsonDataList = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; NSData *_rpJsonDataList = [NSURLConnection sendSynchronousRequest:_rqJsonDataList returningResponse:nil error:nil]; NSString *_strJsonDataList = [[NSString alloc] initWithData:_rpJsonDataList encoding:NSUTF8StringEncoding]; NSDictionary *_nsDicJsonDataList = [_strJsonDataList JSONValue]; NSString *_strStatusCode = [_nsDicJsonDataList objectForKey:@"StatusCode"]; NSString *_strStatusMessage = [_nsDicJsonDataList objectForKey:@"StatusMessage"]; // OK if ([_strStatusCode isEqualToString:@"OK"]) { NSArray *_arrList = [_nsDicJsonDataList objectForKey:@"Table1"]; [self._arrSearchNews removeAllObjects]; [self._arrSearchNews addObjectsFromArray:_arrList]; } // Error else { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:_strStatusMessage delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK",nil]; [alert show]; } } #pragma mark - [UITableView] Number of Sections - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } #pragma mark - [UITableView] Number of Rows In Section - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { int _retValue = 0; _retValue = [_arrSearchNews count]; return _retValue; } #pragma mark - [UITableView] Return table view cell - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"mnuSearchCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier]; } // Set font UIFont *textLabelFont = [UIFont fontWithName:@"Helvetica" size:14]; cell.textLabel.font = textLabelFont; UIFont *detailTextLabelFont = [UIFont fontWithName:@"Helvetica" size:12]; cell.detailTextLabel.font = detailTextLabelFont; cell.imageView.image = nil; NSDictionary *_nsDic = [self._arrSearchNews objectAtIndex:indexPath.row]; NSString *abc = [NSString stringWithFormat:@"[%@] %@", [_nsDic objectForKey:@"GUBUN_NM"], [_nsDic objectForKey:@"TSUBJECT"]]; NSLog(@"%@", abc); **//--&gt; This returns text I wanted.** cell.textLabel.text = [NSString stringWithFormat:@"[%@] %@", [_nsDic objectForKey:@"GUBUN_NM"], [_nsDic objectForKey:@"TSUBJECT"]]; cell.detailTextLabel.text = nil; return cell; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; self._arrSearchNews = [[NSMutableArray alloc] init]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)viewDidUnload { [self setTblNewsSearch:nil]; [self setTxtSearchBox:nil]; [super viewDidUnload]; } @end </code></pre> <p>I really don't understand why my UITableView does not return any data. When I type in some keywords in Search Box, it shows me "No Results". And when I click "Search" in keyboard, my app gets data from json. "_arrSearchNews" has got 340 objects. But UITableView still remains with "No Results". Please help me with this error. Thanks in advance.</p>
 

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