我的故事板是這樣的:UITableView的空白單元格
正如你所看到的,我的MapView低於TableView中,然後當我點擊搜索欄上的另一個TableView中會出現。
我的代碼:
.H
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface STLMMeetupLocation : UIViewController <UITextFieldDelegate, UITableViewDataSource, UITableViewDataSource, MKMapViewDelegate, CLLocationManagerDelegate, UISearchBarDelegate, UISearchDisplayDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
@end
.M
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.tableView)
{
static NSString *cellIdentifier = @"firstTableViewCell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = @"This is a First Table View cell";
return cell;
}
else {
static NSString *cellIdentifier = @"searchBarCell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = @"This is a Search Bar cell";
return cell;
}
}
我的模擬器第一屏:
我的模擬器上或者第二屏幕:
爲什麼我的模擬器首先屏幕的的tableView的cell.textLabel.text空白?它不應該有@「這是第一個表格視圖單元格」;我知道我在做一些愚蠢的事情!
你的問題是第一次正確嗎? - 當出現上面的屏幕時,會出現空白表格視圖,並且在搜索欄上單擊後可見。 – 2013-04-11 04:15:53
你什麼意思是第一次? – user1107173 2013-04-11 04:16:50
沒有。通過點擊取消按鈕,我可以在第一個屏幕和第二個屏幕之間來回切換,並且第一個屏幕上的TableView保持空白。 – user1107173 2013-04-11 04:18:21