FirstPage.h我的tableview的細胞沒有顯示
#import <UIKit/UIKit.h>
#import "StudentPage.h"
@interface FirstPage : UIViewController <UITableViewDelegate,UITableViewDataSource,StudentInfoDelegates>
@property (strong, nonatomic) IBOutlet UITableView *tableView;
- (IBAction)addButtonAction:(id)sender;
@end
FirstPage.m
#import "FirstPage.h"
@interface FirstPage()
@end
@implementation FirstPage
{
NSMutableArray *firstPageArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib
//[self performSegueWithIdentifier:@"StudentInfo" sender:sender];
/*StudentPage *student=[[StudentPage alloc]init];
student.delegates=self;*/
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//the next following didn't created..
//the RowAtIndexPath are not been executed..
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *[email protected]"";
NSMutableDictionary *studentSecondDictionary=[[NSMutableDictionary alloc]init];
static NSString *[email protected]"Cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
cell=[[UITableViewCell alloc]initWithFrame:CGRectZero];
[cell setBackgroundColor:[UIColor redColor]];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell setIndentationWidth:0.0];
studentSecondDictionary=[firstPageArray objectAtIndex:indexPath.row];
NSString *name1=[studentSecondDictionary valueForKey:@"NAME"];
NSString *regno1=[studentSecondDictionary valueForKey:@"REGNO"];
NSString *marks1=[studentSecondDictionary valueForKey:@"MARKS"];
NSString *rank1=[studentSecondDictionary valueForKey:@"RANK"];
concateValue=[[[[[[name1 stringByAppendingString:@" "]stringByAppendingString:regno1]stringByAppendingString:@" "]stringByAppendingString:marks1]stringByAppendingString:@" "]stringByAppendingString:rank1];
cell.textLabel.text=concateValue;
}
return cell;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return firstPageArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 50;
}
- (IBAction)addButtonAction:(id)sender {
StudentPage *stdView=[self.storyboard instantiateViewControllerWithIdentifier:@"MyIdentifier"];
stdView.delegates=self;
[self.navigationController pushViewController:stdView animated:YES];
//[self.view addSubview:stdView.view];
}
-(void)didFinishSave:(NSMutableArray *)in_studentList{
firstPageArray=[[NSMutableArray alloc]init];
firstPageArray=in_studentList;
[self.tableView reloadData];
}
@end
StudentPage.h
#import <UIKit/UIKit.h>
@protocol StudentInfoDelegates
-(void)didFinishSave:(NSMutableArray*)in_studentList;
@end
@interface StudentPage : UIViewController<UITextFieldDelegate>
@property(assign,nonatomic)id<StudentInfoDelegates> delegates;
@property (strong, nonatomic) IBOutlet UITextField *name;
@property (strong, nonatomic) IBOutlet UITextField *regno;
@property (strong, nonatomic) IBOutlet UITextField *marks;
@property (strong, nonatomic) IBOutlet UITextField *rank;
- (IBAction)save:(UIButton *)sender;
@end
StudentPage.m
#import "StudentPage.h"
#import "FirstPage.h"
@implementation StudentPage
{
NSMutableArray *studentArray;
NSMutableDictionary *StudentDictionary;
}
@synthesize name,regno,marks,rank;
@synthesize delegates;
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
[super touchesBegan:touches withEvent:event];
}
- (IBAction)save:(UIButton *)sender {
studentArray=[[NSMutableArray alloc]init];
StudentDictionary=[[NSMutableDictionary alloc]init];
[StudentDictionary setValue:name.text forKey:@"NAME"];
[StudentDictionary setValue:regno.text forKey:@"REGNO"];
[StudentDictionary setValue:marks.text forKey:@"MARKS"];
[StudentDictionary setValue:rank.text forKey:@"RANK"];
[studentArray addObject:StudentDictionary];
[delegates didFinishSave:studentArray];
NSLog(@"%@",studentArray);
FirstPage *firstView=[self.storyboard instantiateViewControllerWithIdentifier:@"MyIdentifier1"];
[self.navigationController pushViewController:firstView animated:YES];
}
@end
請首先正確格式化您的代碼 – Natasha
您是否爲表視圖連接了'delegate'和'datasource'? – Gandalf
是的,我連接了我的表格視圖的代表和數據源 –