【发布时间】:2015-07-14 12:10:10
【问题描述】:
我有一个 SecondViewController 作为滑动面板,它有一个 UITableView 并使用从 ViewController.Running 的“getnotes”函数返回的 NSArray 数据填充它,它第一次获取所有数据,但是当插入新数据时 UITableView 不会更新虽然 NSArray "n" 包含新数据。
这里是 SecondViewController.h-
#import <UIKit/UIKit.h>
@interface SecondViewController:UIViewController<UITableViewDelegate,UITableViewDataSource>
{
NSArray *n;
}
@property (strong, nonatomic) IBOutlet UITableView *tableview;
-(void)gets;
@end
这里是 SecondViewController.m-
#import "SecondViewController.h"
#import "ViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self gets];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma Table View Methods
-(void)gets{
ViewController *dba=[[ViewController alloc]init];
n = [NSArray arrayWithArray:[dba getnotes]];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section{
if(n==nil)return 0;
return n.count;
}
-(UITableViewCell *)tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellID=@"cellID";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
if(cell==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
}
NSDictionary * res =[n objectAtIndex:indexPath.row];
cell.textLabel.text=[res objectForKey:@"NoteText"];
cell.detailTextLabel.text=[NSString stringWithFormat:@"%@" ,[res objectForKey:@"NoteDate"]];
return cell;
}
@end
问题出在哪里?
更新:好的..我不知道它是对还是错,但我调用了gets函数,然后在viewWillAppear方法中重新加载了tableview并且它起作用了:)
【问题讨论】:
-
您如何从
ViewController显示SecondViewController? -
为此生成通知
-
secondviewcontroller 是一个半滑动面板......就像手机中的 facebook 一样。 @Akhhilrajtr
标签: ios objective-c uitableview