2

我在我的某一行部分中将所选数据显示到 detaillabeltext 中时遇到问题,除了重新加载整个表格视图之外,还有其他方法可以仅重新加载部分的特定行吗?

//RootViewController.m(父控制器)

-(void) selectedData:(NSString*) text
{
  selectedAbsenceType = text;

  NSLog(@"the absence type select is %@",text);
}

-(void) (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    if (indexPath.section == 0)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
}

NSDictionary *dictionary = [dataArray objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"data"];
NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;

if([cellValue isEqual: @"Absence Type"])
{
    cell.detailTextLabel.text = selectedAbsenceType;
}
else if([cellValue isEqual:@"Start Date"])
{
    cell.detailTextLabel.text = selectedDate;
}
return cell;

}

==================================================== ========================================== 我在调用方法时遇到问题协议,它在这个声明中不断提示我一个 ARC 语义问题

[self.delegate selectedData: (NSString*) [self.absenceTypes objectAtIndex:indexPath.row]];:

//child.h

#import <UIKit/UIKit.h>

@protocol childViewControllerDelegate;

@interface AbsenceTypesViewController : UITableViewController
{
   id<childViewControllerDelegate>delegate;
}
@property (nonatomic,weak) id<childViewControllerDelegate> delegate;
@property NSArray *absenceTypes;
@end

@protocol childViewControllerDelegate <NSObject>
-(void) selectedData:(NSString*) text;
@end

//child.m

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath    *)indexPath
{

NSString *selectedCell = nil;
selectedCell = [self.absenceTypes objectAtIndex:indexPath.row];

[self.delegate selectedData: (NSString*) [self.absenceTypes objectAtIndex:indexPath.row]];

//[self.navigationController popViewControllerAnimated:YES];
NSLog(@"%@", selectedCell);

}
4

2 回答 2

0
 You can save all selected option of second view controller in NSMutable Array and save all components  separated by comma and send this array to your parent controller.

 NSMutableArray *selectedVal =[[NSMutableArray alloc] init];

      FirstViewController *FVC = (FirstViewController*)

         if ([FVC isKindOfClass:[FirstViewController class]])
         {

             [FVC setSelectedOption:[selectedVal componentsJoinedByString:@","]];


         }

         [self.navigationController popViewControllerAnimated:YES];   
于 2013-06-17T05:23:39.887 回答
0

删除{ id<childViewControllerDelegate>delegate; }内部用户类界面。id<childViewControllerDelegate>delegate;表示强变量,只有在释放持有对象时才会释放。但是在属性声明中,您提到委托是弱属性。因此,ARC Semantic 正在给你警告。您还可以通过将委托明确声明为弱来使委托变得弱,例如__weak id<childViewControllerDelegate>delegate;

尝试用这个替换 .h 文件内容。

#import <UIKit/UIKit.h>  
@class AbsenceTypesViewController;

@protocol childViewControllerDelegate <NSObject>
-(void) selectedData:(NSString*) text;
@end

@interface AbsenceTypesViewController : UITableViewController
{
   id<childViewControllerDelegate>delegate;
}
@property (nonatomic,weak) id<childViewControllerDelegate> delegate;
@property NSArray *absenceTypes;
@end

这样你就有了类的前向声明。

于 2013-06-14T12:55:11.023 回答