Iphone 为什么我的tableView是空白的?我是否没有正确地重新加载数据源?
Iphone 为什么我的tableView是空白的?我是否没有正确地重新加载数据源?,iphone,ios,objective-c,Iphone,Ios,Objective C,视图中的NSLog将出现和numberOfRowsInSection都显示了我想在tableView中填充的数据 我认为这个问题与返回正确的计数有关,但是,由于NSLogs匹配,我不确定这就是问题所在 另外,我认为这是问题所在,因为没有调用cellforrowatinexpath 我没有正确地重新加载tableView吗?非常感谢你的帮助 #import "MainQueryViewController.h" #import <Parse/Parse.h> #import "SVPr
视图中的NSLog将出现
和numberOfRowsInSection
都显示了我想在tableView中填充的数据
我认为这个问题与返回正确的计数有关,但是,由于NSLogs匹配,我不确定这就是问题所在
另外,我认为这是问题所在,因为没有调用cellforrowatinexpath
我没有正确地重新加载tableView吗?非常感谢你的帮助
#import "MainQueryViewController.h"
#import <Parse/Parse.h>
#import "SVProgressHUD.h"
#import "HHPanningTableViewCell.h"
#import "HHInnerShadowView.h"
#import "HHDirectionPanGestureRecognizer.h"
@interface MainQueryViewController () <PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate, HHPanningTableViewCellDelegate>
@end
@implementation MainQueryViewController
@synthesize listArray;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
PFLogInViewController *login = [[PFLogInViewController alloc] init];
login.fields = PFLogInFieldsFacebook;
login.delegate = self;
login.signUpController.delegate = self;
[self presentModalViewController:login animated:NO];
}
-(void)viewWillAppear:(BOOL)animated {
PFQuery *query = [PFQuery queryWithClassName:@"ListItem"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
[query whereKey:@"listName" equalTo:[PFUser currentUser]];
listArray = [objects mutableCopy];
NSLog(@"I'm about to show you an array");
NSLog(@"%@", listArray);
}
else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
HHPanningTableViewCell *cell = (HHPanningTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSInteger directionMask = indexPath.row % 5;
if (cell == nil) {
NSLog(@"Cell = nil.");
cell = [[HHPanningTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
UIView *drawerView = [[UIView alloc] initWithFrame:cell.frame];
drawerView.backgroundColor = [UIColor greenColor];
cell.textLabel.text = [listArray objectAtIndex:indexPath.row];
cell.drawerView = drawerView;
// Configure the cell...
}
if (directionMask < 3) {
cell.directionMask = directionMask;
}
else {
cell.directionMask = HHPanningTableViewCellDirectionLeft + HHPanningTableViewCellDirectionRight;
if (directionMask == 4) {
cell.delegate = self;
}
}
cell.textLabel.text = [self.listArray objectAtIndex:directionMask];
return cell;
}
#pragma mark - PFLogInViewController delegate
- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user
{
[self dismissViewControllerAnimated:YES completion:^{
NSLog(@"Successfully logged in.");
[SVProgressHUD showSuccessWithStatus:@"Success!"];
}];
}
- (void)logInViewControllerDidCancelLogIn:(PFLogInViewController *)logInController
{
[self dismissModalViewControllerAnimated:YES];
NSLog(@"Login was cancelled!");
}
- (void)signUpViewController:(PFSignUpViewController *)signUpController didSignUpUser:(PFUser *)user
{
[self dismissModalViewControllerAnimated:YES];
NSLog(@"Successfully signed up.");
}
- (void)signUpViewControllerDidCancelSignUp:(PFSignUpViewController *)signUpController
{
[self dismissModalViewControllerAnimated:YES];
NSLog(@"Sign up was cancelled!");
}
#pragma mark - Table view delegate
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell isKindOfClass:[HHPanningTableViewCell class]]) {
HHPanningTableViewCell *panningTableViewCell = (HHPanningTableViewCell*)cell;
if ([panningTableViewCell isDrawerRevealed]) {
return nil;
}
}
return indexPath;
}
- (void)panningTableViewCellDidTrigger:(HHPanningTableViewCell *)cell inDirection:(HHPanningTableViewCellDirection)direction
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Custom Action"
message:@"You triggered a custom action"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
PFQuery *query = [PFQuery queryWithClassName:@"ListItem"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
[query whereKey:@"listName" equalTo:[PFUser currentUser]];
listArray = [objects mutableCopy];
NSLog(@"I'm about to show you an array");
NSLog(@"%@", listArray);
}
else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
NSLog(@"This is a count of listArray");
NSLog(@"%@", listArray);
return [listArray count];
}
@end
#导入“MainQueryViewController.h”
#进口
#导入“SVProgressHUD.h”
#导入“HHPanningTableViewCell.h”
#导入“HHInnerShadowView.h”
#导入“hhDirectionPangestureRecognitor.h”
@接口MainQueryViewController()
@结束
@实现MainQueryViewController
@综合列表阵列;
-(id)initWithStyle:(UITableViewStyle)样式
{
self=[super initWithStyle:style];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)viewDidLoad
{
[超级视图下载];
PFLogInViewController*login=[[PFLogInViewController alloc]init];
login.fields=PFLogInFieldsFacebook;
login.delegate=self;
login.signUpController.delegate=self;
[自我呈现Modalviewcontroller:登录动画:否];
}
-(无效)视图将显示:(BOOL)动画{
PFQuery*query=[PFQuery queryWithClassName:@“ListItem”];
[查询findObjectsInBackgroundWithBlock:^(NSArray*对象,NSError*错误){
如果(!错误){
[query whereKey:@“listName”等于:[PFUser currentUser]];
listArray=[objects mutableCopy];
NSLog(@“我将向您展示一个数组”);
NSLog(@“%@”,列表数组);
}
否则{
NSLog(@“Error:%@”,Error,[Error userInfo]);
}
}];
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
#pragma标记-表视图数据源
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
//返回节数。
返回1;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
HHPanningTableViewCell*单元格=(HHPanningTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSInteger directionMask=indexPath.row%5;
如果(单元格==nil){
NSLog(@“Cell=nil”);
cell=[[HHPanningTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier];
UIView*DroperView=[[UIView alloc]initWithFrame:cell.frame];
drawerView.backgroundColor=[UIColor-greenColor];
cell.textlab.text=[listArray objectAtIndex:indexath.row];
cell.drawerView=drawerView;
//配置单元格。。。
}
if(方向掩码<3){
cell.directionMask=方向掩码;
}
否则{
cell.directionMask=HHPanningTableViewCellDirectionLeft+HHPanningTableViewCellDirectionRight;
如果(方向掩码==4){
cell.delegate=self;
}
}
cell.textlab.text=[self.listary objectAtIndex:directionMask];
返回单元;
}
#pragma标记-PFLogInViewController委托
-(无效)logInViewController:(PFLogInViewController*)logInController didLogInUser:(PFUser*)用户
{
[自我解除查看控制器激活:是完成:^{
NSLog(@“已成功登录”);
[SVProgressHUD showSuccessWithStatus:@“成功!”;
}];
}
-(无效)LoginViewController IDCancelLogin:(PFLogInViewController*)logInController
{
[自我解散Modalviewcontrolleranimated:是];
NSLog(@“登录已取消!”);
}
-(void)signUpViewController:(PFSignUpViewController*)signUpController didSignUpUser:(PFUser*)用户
{
[自我解散Modalviewcontrolleranimated:是];
NSLog(@“已成功注册”);
}
-(无效)SignupViewControllerIDCancelSignup:(PFSignUpViewController*)signUpController
{
[自我解散Modalviewcontrolleranimated:是];
NSLog(@“注册已取消!”);
}
#pragma标记-表视图委托
-(NSIndexPath*)tableView:(UITableView*)tableView将选择RowatineXpath:(NSIndexPath*)indexPath{
UITableViewCell*单元格=[tableView cellForRowAtIndexPath:indexPath];
if([cell iskindof类:[HHPanningTableViewCell类]]){
HHPanningTableViewCell*panningTableViewCell=(HHPanningTableViewCell*)单元格;
如果([panningTableViewCell IsDrawerRevaled]){
返回零;
}
}
返回索引XPath;
}
-(void)panningTableViewCellDidTrigger:(HHPanningTableViewCell*)单元格间接:(HHPanningTableViewCellDirection)方向
{
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“自定义操作”
消息:@“您触发了自定义操作”
代表:无
取消按钮:@“确定”
其他按钮:无];
[警报显示];
}
#pragma标记-UITableViewDelegate
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath{
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
PFQuery*query=[PFQuery queryWithClassName:@“ListItem”];
[查询findObjectsInBackgroundWithBlock:^(NSArray*对象,NSError*错误){
如果(!错误){
[query whereKey:@“listName”等于:[PFUser currentUser]];
listArray=[objects mutableCopy];
NSLog(@“我将向您展示一个数组”);
NSLog(@“%@”,列表数组);
}
否则{
NSLog(@“Error:%@”,Error,[Error userInfo]);
}
}];
NSLog(@“这是listArray的计数”);
NSLog(@“%@”,列表数组);
返回[listArray计数];
}
@结束
获取数据后重新加载表视图: 添加此行:
listArray = [objects mutableCopy];
[tableView reloadData]