Ios 为什么我的UITableView不能完全加载传感器内容?

Ios 为什么我的UITableView不能完全加载传感器内容?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,似乎我的表加载了一部分,其余的在我上下滚动几次后加载。毫无疑问,这与我的[[self-myTableView]reloadData]有关和我在-(void)视图之间的位置将出现:(BOOL)动画,-(void)viewdide出现:(BOOL)动画,-(void)viewdideload,尽管我无法用手指触摸它。在这种情况下,没有要求提供数据;我只是尝试在应用程序启动时一次加载所有指定的数据 #import "PreViewController.h" #import <CoreData/C

似乎我的表加载了一部分,其余的在我上下滚动几次后加载。毫无疑问,这与我的
[[self-myTableView]reloadData]有关和我在
-(void)视图之间的位置将出现:(BOOL)动画,-(void)viewdide出现:(BOOL)动画,-(void)viewdideload
,尽管我无法用手指触摸它。在这种情况下,没有要求提供数据;我只是尝试在应用程序启动时一次加载所有指定的数据

#import "PreViewController.h"
#import <CoreData/CoreData.h>
#import <CoreLocation/CoreLocation.h>
#import "FlipsideViewController.h"
#import "AppDelegate.h"
#import <SystemConfiguration/SystemConfiguration.h>
#import "Reachability.h"

@interface PreViewController ()

{
    NSMutableArray *arrayNo;
}

@end

@implementation PreViewController

-(void)viewWillAppear:(BOOL)animated
{
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkForReachability) name:kReachabilityChangedNotification object:nil];

    Reachability *reachability = [Reachability reachabilityForInternetConnection];
    [reachability startNotifier];

    NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];

    if(remoteHostStatus == NotReachable)
    {
        UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle: @"Please check your network connection and try again."
                          message: @""
                          delegate: nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
        [alert show];
    }
 }

-(void)viewDidAppear:(BOOL)animated
{    

   NSString *arts = [NSString stringWithFormat:@"Arts and Museums"];
   NSString *coffee = [NSString stringWithFormat:@"Coffee and Bakeries"];
   NSString *tours = [NSString stringWithFormat:@"Tours and Festivals"];
   NSString *hotels = [NSString stringWithFormat:@"Hotels and Inns"];
   NSString *leisure = [NSString stringWithFormat:@"Leisure and Recreation"];
   NSString *music = [NSString stringWithFormat:@"Live Music"];
   NSString *bars = [NSString stringWithFormat:@"Night Clubs and Bars"];
   NSString *food = [NSString stringWithFormat:@"Restaurants"];
   NSString *shopping = [NSString stringWithFormat:@"Shopping"];
   NSString *transportation = [NSString stringWithFormat:@"Transportation"];

   [arrayNo addObject:arts];
   [arrayNo addObject:coffee];
   [arrayNo addObject:tours];
   [arrayNo addObject:hotels];
   [arrayNo addObject:leisure];
   [arrayNo addObject:music];
   [arrayNo addObject:bars];
   [arrayNo addObject:food];
   [arrayNo addObject:shopping];
   [arrayNo addObject:transportation];

   [[self myTableView] reloadData];
}

- (void)viewDidLoad
{
   [super viewDidLoad];
   arrayNo = [[NSMutableArray alloc] init];

   [[self myTableView] setDelegate:self];
   [[self myTableView] setDataSource:self];
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
   return 1;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [arrayNo count];
}

- (UIFont *)fontForCell
{
   return [UIFont boldSystemFontOfSize:14.0];
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"Cell";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

  if (!cell)
  {
      NSLog(@"CREATING NEW CELL");
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  }
  else
  {
      cell.textLabel.text = [arrayNo objectAtIndex:indexPath.row];
      cell.textLabel.textColor = [UIColor whiteColor];
      cell.textLabel.textAlignment = NSTextAlignmentCenter;
      cell.textLabel.textColor = [UIColor colorWithRed:(100/255.0) green:(130/255.0) blue:(255/255.0) alpha:1.0];
  }
  return cell;
}


- (void)didReceiveMemoryWarning
{
  [super didReceiveMemoryWarning];
}

@end
#导入“PreViewController.h”
#进口
#进口
#导入“FlipsideViewController.h”
#导入“AppDelegate.h”
#进口
#导入“可达性.h”
@接口预览控制器()
{
NSMutableArray*arrayNo;
}
@结束
@实现预览控制器
-(无效)视图将显示:(BOOL)动画
{
[[NSNotificationCenter defaultCenter]addObserver:自选择器:@selector(checkForReachability)名称:kReachabilityChangedNotification对象:nil];
可达性*可达性=[可达性可达性Internet连接];
[可达性启动通知];
NetworkStatus remoteHostStatus=[reachability currentReachabilityStatus];
if(remoteHostStatus==不可访问)
{
UIAlertView*警报=[[UIAlertView alloc]
initWithTitle:@“请检查您的网络连接并重试。”
消息:@“”
代表:无
取消按钮:@“确定”
其他按钮:无];
[警报显示];
}
}
-(无效)视图显示:(BOOL)动画
{    
NSString*arts=[NSString stringWithFormat:@“艺术与博物馆”];
NSString*coffee=[NSString stringWithFormat:@“咖啡和面包店”];
NSString*tours=[NSString stringWithFormat:@“旅游和节日”];
NSString*hotels=[NSString stringWithFormat:@“hotels and Inns”];
NSString*leisure=[NSString stringWithFormat:@“休闲娱乐”];
NSString*music=[NSString stringWithFormat:@“现场音乐”];
NSString*bars=[NSString stringWithFormat:@“夜总会和酒吧”];
NSString*food=[NSString stringWithFormat:@“餐厅”];
NSString*购物=[NSString stringWithFormat:@“购物”];
NSString*传输=[NSString stringWithFormat:@“传输”];
[arrayNo addObject:arts];
[arrayNo addObject:咖啡];
[arrayNo addObject:tours];
[arrayNo addObject:酒店];
[arrayNo addObject:休闲];
[arrayNo addObject:音乐];
[arrayNo addObject:bars];
[arrayNo addObject:食物];
[arrayNo addObject:购物];
[arrayNo addObject:transportation];
[[self myTableView]重新加载数据];
}
-(无效)viewDidLoad
{
[超级视图下载];
arrayNo=[[NSMutableArray alloc]init];
[[self myTableView]setDelegate:self];
[[self myTableView]setDataSource:self];
}
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
返回[arrayNo count];
}
-(UIFont*)fontForCell
{
返回[UIFont boldSystemFontOfSize:14.0];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(!单元格)
{
NSLog(@“创建新单元”);
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier];
}
其他的
{
cell.textlab.text=[arrayNo objectAtIndex:indexath.row];
cell.textLabel.textColor=[UIColor whiteColor];
cell.textLabel.textAlignment=NSTextAlignmentCenter;
cell.textlab.textColor=[UIColor colorWithRed:(100/255.0)green:(130/255.0)blue:(255/255.0)alpha:1.0];
}
返回单元;
}
-(无效)未收到记忆警告
{
[超级记忆警告];
}
@结束

在tableView cellForRowAtIndexPath:method中,按如下方式更改代码(您的else部分不正确)


在tableView cellForRowAtIndexPath:method中,更改如下代码(您的else部分不正确)


暂时禁用ViewWillAspect方法中的所有代码,看看问题是否消失。我复制了ViewWillAspect方法之外的所有内容,对我来说效果很好。为什么要等到
ViewDidAspect:
加载数组?旁注-请取消对
stringWithFormat:
的所有调用。只有当您实际有需要格式化的字符串时,才使用
stringWithFormat:
。示例:
NSString arts=@“艺术与博物馆”。我想我不明白拍摄
视图会如何影响它?也许我需要更新到最新版本的XCode…我也不需要。我也不确定你接受的答案中有什么帮助。“其他”部分没有问题。当你按照Thilina建议的方式进行操作时,是否会收到蓝色文本?暂时禁用viewWillAppear方法中的所有代码,看看问题是否消失。我复制了viewWillAppear方法之外的所有内容,它对我来说工作正常。为什么要等到
viewDidAppear:
加载数组?旁注-请取消对
stringWithFormat:
的所有调用。只有当您实际有需要格式化的字符串时,才使用
stringWithFormat:
。示例:
NSString arts=@“艺术与博物馆”。我想我不明白拍摄
视图会如何影响它?也许我需要更新到最新版本的XCode…我也不需要。我也不确定你接受的答案中有什么帮助。“其他”部分没有问题。当你按照Thilina建议的方式做时,会收到蓝色文本吗?谢谢Thilina!据我所知,删除
else
对我很有效。else部分有什么不正确之处?如果他在sto中执行表视图控制器,则if部分中的代码甚至不会运行
    if (!cell)
      {
         NSLog(@"CREATING NEW CELL");
         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
         cell.textLabel.textColor = [UIColor whiteColor];
         cell.textLabel.textAlignment = NSTextAlignmentCenter;
         cell.textLabel.textColor = [UIColor colorWithRed:(100/255.0) green:(130/255.0) blue:(255/255.0) alpha:1.0];
      }

  cell.textLabel.text = [arrayNo objectAtIndex:indexPath.row];