我.h
文件:iOS:爲什麼第二部分不顯示在UITableView中?
@interface ViewPrescriptionViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
@property(weak, nonatomic) NSArray *arr;
@property (nonatomic, retain) NSArray *menuItems;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, retain) NSArray *medicineItems;
@end
我.m
文件:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
/* Here i send parameter to server using AFNetworking, and i got response from server ,
menu_itemes: (
{
bp = "000/000";
dateTime = "05/12/2016 01:02:59 PM";
doc = {
"email_id" = "[email protected]";
exception = 0;
gender = Male;
id = 0;
"mobile_no" = 1234567890;
name = Batra;
"profile_id" = 0;
qualification = "MD(Doctor)";
"reg_id" = 157;
salutation = Mr;
"wellness_id" = 251215782521;
};
"follow_up" = 17;
id = 37;
medicine = (
"Syrup,Decold Total,20,0-0-1,Before Meal,1",
"Injection,Insulin,1,0-0-1,Before Meal,1",
no,
no,
no,
no,
no,
no,
no,
no
);
patient = {
"email_id" = "[email protected]";
exception = 0;
gender = Male;
id = 0;
"mobile_no" = 1234567890;
name = Rohit;
"profile_id" = 0;
qualification = "";
"reg_id" = 150;
salutation = Mr;
"wellness_id" = 290119935030;
};
weight = 000;
}
)
*/
[manager POST:Loginurl parameters:params progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"Response from view Prescription server : %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);
// [email protected][@"%@",[[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]];
NSArray *ResponseArray = [NSJSONSerialization JSONObjectWithData: responseObject options: kNilOptions error: nil];
if (ResponseArray.count >0)
{
self.menuItems = [[NSMutableArray alloc]initWithArray:ResponseArray];
[_tableView reloadData];
//menuItems = [ResponseArray mutableCopy];
NSLog(@"menu_itemes: %@",self.menuItems);
}
NSMutableArray *Myarray = [NSMutableArray new];
for (int i=0; i<_menuItems.count; i++) {
[Myarray addObject:[[_menuItems objectAtIndex:i] objectForKey:@"medicine"]];
NSLog(@"medicine: %@",Myarray);
}
if (Myarray.count>0) {
self.medicineItems=[NSArray arrayWithArray:Myarray];
//[_tableView reloadData];
NSLog(@"medicine items : %@",self.medicineItems);
NSLog(@"medicine items count : %lu",(unsigned long)self.medicineItems.count);
}
// _arr=[NSArray arrayWithArray:ResponseArray];
// NSLog(@"menu_itemes: %@",_menuItems);
[self getdata:responseObject];
} failure:^(NSURLSessionTask *operation, NSError *error)
{
...... 然後
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)
{
return 1;
}
else
{
NSLog(@"S");
//here is breakpoint
return self.medicineItems.count;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0)
{
NSDictionary *content = [self.menuItems objectAtIndex:indexPath.row];
NSLog(@"content = %@",content);
ViewPrescriptionTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"PatientDetail" forIndexPath:indexPath];
[cell.datetime setText:[content valueForKey:@"dateTime"]];
[cell.bp setText:[content valueForKey:@"bp"]];
[cell.weight setText:[content valueForKey:@"weight"]];
[cell.followup setText:[content valueForKey:@"follow_up"]];
[cell.doctorname setText:[[content objectForKey:@"doc"]valueForKey:@"name"]];
[cell.mobile setText:[NSString stringWithFormat:@"%@",[[content objectForKey:@"doc"]valueForKey:@"mobile_no"]]];
[cell.email setText:[[content objectForKey:@"doc"]valueForKey:@"email_id"]];
[cell.qualification setText:[[content objectForKey:@"doc"]valueForKey:@"qualification"]];
[cell.wellnessid setText:[[content objectForKey:@"doc"]valueForKey:@"wellness_id"]];
[cell.patientname setText:[[content objectForKey:@"patient"]valueForKey:@"name"]];
[cell.patientmobile setText:[NSString stringWithFormat:@"%@",[[content objectForKey:@"patient"]valueForKey:@"mobile_no"]]];
[cell.patientemail setText:[[content objectForKey:@"patient"]valueForKey:@"email_id"]];
[cell.patientwellnessid setText:[[content objectForKey:@"patient"]valueForKey:@"wellness_id"]];
return cell;
}
else{
//Cell For Medicines
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"PatientDetail" forIndexPath:indexPath];
NSLog(@"s");
//here is breakpoint
[cell.textLabel setText:[self.medicineItems objectAtIndex:indexPath.row]];
return cell;
}
}
在故事板
我在屏幕上爲此拍攝了UITableView
。
我已經爲此採取了1個靜態自定義單元格。
我想要什麼:
我想要兩個部分,在第一,我顯示這是我從服務器接收的所有數據,除了medicinItems
像下面的圖片:
在第二部分,
我想通過medicinItems
那。
但我的問題是,第二節沒有移位。
但我不知道該怎麼做.. ??
請任何人都可以解決我的問題。幫助將是可觀的。
是「self.medicineItems.count」返回的數字大於0嗎?你有沒有嘗試過在那裏放一個1? – pflous
是的,我試過,但它不工作 –
if(section == 0){return 1; } else { NSLog(@「S」); //這裏是斷點 return self.medicineItems.count; } ...這裏它來在其他地方... @ pflous –