我在uitableview中有两个pickerview,当你选择选择器时,它旁边的标签会显示值。代码在第一个pickerview中正常运行,但第二个当你选择标签时没有显示任何值,我试过nslog但它打印的值意味着值isnt null
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"Cell"];
cell.accessoryType = UITableViewCellAccessoryNone;
if ([indexPath section] == 0) {
CGRect frame = CGRectMake(160, 10, 585, 30);
name = [[UITextField alloc]initWithFrame:frame];
email = [[UITextField alloc]initWithFrame:frame];
phone = [[UITextField alloc]initWithFrame:frame];
if ([indexPath row] == 0) {
name.keyboardType = UIKeyboardTypeEmailAddress;
name.returnKeyType = UIReturnKeyNext;
}
if([indexPath row]==1){
email.keyboardType = UIKeyboardTypeDefault;
email.returnKeyType = UIReturnKeyDone;
email.secureTextEntry = YES;
}
if([indexPath row]==2)
{
phone.keyboardType = UIKeyboardTypeDefault;
phone.returnKeyType = UIReturnKeyDone;
phone.secureTextEntry = YES;
}
[cell addSubview:name];
[cell addSubview:email];
[cell addSubview:phone];
if ([indexPath row] == 0) {
cell.textLabel.text = @"Name";
}
if([indexPath row]==1)
{
cell.textLabel.text = @"Email";
}
if([indexPath row]==2)
{
cell.textLabel.text = @"Phone";
}
}
}
if([indexPath section]==1)
{
packlist = [[UIButton alloc]initWithFrame:CGRectMake(680, 0, 50, 45)];
package_selected = [[UILabel alloc]initWithFrame:CGRectMake(380, 0, 250, 45)];
if([indexPath row]==0)
{
[packlist setBackgroundImage:[UIImage imageNamed:@"drp-down-bt1.png"] forState:UIControlStateNormal];
[packlist addTarget:self
action:@selector(packagelist)
forControlEvents:UIControlEventTouchUpInside];
[package_selected setBackgroundColor:[UIColor clearColor]];
cell.textLabel.text = @"Select Package";
[cell addSubview:packlist];
[cell addSubview:package_selected];
}
}
if([indexPath section]==2)
{
if([[add_on_require objectAtIndex:0] count]>0)
{
add_req_button = [[UIButton alloc]initWithFrame:CGRectMake(680, 0, 50, 45)];
require_label = [[UILabel alloc]initWithFrame:CGRectMake(380, 0, 250, 45)];
for(int i=0;i<[[add_on_require objectAtIndex:0] count];i++)
{
if([indexPath row]==0)
{
[add_req_button setBackgroundImage:[UIImage imageNamed:@"drp-down-bt1.png"] forState:UIControlStateNormal];
[add_req_button addTarget:self
action:@selector(requirelist)
forControlEvents:UIControlEventTouchUpInside];
[require_label setBackgroundColor:[UIColor clearColor]];
cell.textLabel.text = @"Requires";
[cell addSubview:add_req_button];
[cell addSubview:require_label];
}
}
}
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
// tell the picker the title for a given component
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
switch (pickerView.tag) {
case PACKAGE_LIST:
{
return [pack_name_price objectAtIndex:row];
break;
}
case REQUIRE_LIST:
{
return [addon_array objectAtIndex:row];
break;
}
default:
break;
}
return nil;
}
#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (actionSheet.tag == PACKAGE_LIST) {
if ([pickerviewPackageDetail selectedRowInComponent:0] > 1 && [pickerviewPackageDetail selectedRowInComponent:0] < 5 ) {
}
}
if(actionSheet.tag == PACKAGE_LIST)
{
if ([pickerviewAddonRequire selectedRowInComponent:0] == 4 )
{
}
else {
}
}
}
-(void)requirelist
{
UIActionSheet *actionSheet1 = [[UIActionSheet alloc] initWithTitle:@"Requires" delegate:self cancelButtonTitle:@"Done" destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet1.tag = REQUIRE_LIST;
actionSheet1.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet1 addSubview:pickerviewAddonRequire];
[actionSheet1 setFrame:CGRectMake(0, 0, 600, 400)];
[controller.view addSubview:actionSheet1];
if ([popovercontroller isPopoverVisible]) {
[popovercontroller dismissPopoverAnimated:YES];
} else {
//the rectangle here is the frame of the object that presents the popover,
//in this case, the UIButton…
CGRect convertedFrame = [orderTable convertRect:add_req_button.frame toView:self.view];
convertedFrame.size.width = 250;
convertedFrame.size.height = 400;
convertedFrame.origin.y = convertedFrame.origin.y + 145;
[popovercontroller presentPopoverFromRect:convertedFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
}
}
-(void)packagelist
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Package" delegate:self cancelButtonTitle:@"Done" destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet.tag = PACKAGE_LIST;
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet addSubview:pickerviewPackageDetail];
// [actionSheet showInView:self.view];
[actionSheet setFrame:CGRectMake(0, 0, 600, 400)];
[controller.view addSubview:actionSheet];
if ([popovercontroller isPopoverVisible]) {
[popovercontroller dismissPopoverAnimated:YES];
} else {
//the rectangle here is the frame of the object that presents the popover,
//in this case, the UIButton…
CGRect convertedFrame = [orderTable convertRect:packlist.frame toView:self.view];
convertedFrame.size.width = 250;
convertedFrame.size.height = 400;
convertedFrame.origin.y = convertedFrame.origin.y + 50;
[popovercontroller presentPopoverFromRect:convertedFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
}
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component {
switch (pickerView.tag) {
case PACKAGE_LIST:
{
package_selected.text = [pack_name_price objectAtIndex:row];
break;
}
case REQUIRE_LIST:
{
require_label.text = [addon_array objectAtIndex:row];
break;
}
default:
break;
}
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
switch (pickerView.tag) {
case PACKAGE_LIST:
{
return [pack_name count];
break;
}
case REQUIRE_LIST:
{
return [addon_array count];
break;
}
default:
break;
}
return 0;
}
//package start
// package end
-(IBAction)btnport:(id)sender
{
[scrollViewPortfolio setContentOffset:CGPointMake(0, 0)];
[port setSelected:TRUE];
[pack setSelected:FALSE];
[ord setSelected:FALSE];
[self.view addSubview:portview];
[packview removeFromSuperview];
[ordview removeFromSuperview];
}
-(IBAction)btnpack:(id)sender
{
[port setSelected:FALSE];
[pack setSelected:TRUE];
[ord setSelected:FALSE];
[self.view addSubview:packview];
[portview removeFromSuperview];
[ordview removeFromSuperview];
[self loadpackage];
}