2016-01-13 175 views
-2

以下是我的示例代码。如何重新加载tblview(tableview)?请帮帮我。如何重新加载一个表视图行选择然后另一个tableview重新加载?

@interface NewUIViewController : UIViewController<UITableViewDataSource,UITableViewDelegate> 
@property (nonatomic, strong) NSMutableArray *dataArray; 
@property (weak, nonatomic) IBOutlet UITableView *tblview; 
- (IBAction)btnAddRow:(id)sender; 
@property (weak, nonatomic) IBOutlet UITableView *tblviewProject; 
@property (nonatomic, strong) NSMutableArray *projectArray; 
@end 
@interface NewUIViewController() 
    { } 
@end 
@implementation NewUIViewController 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    self.dataArray = [[NSMutableArray alloc] initWithObjects:@"Tiger",@"Leopard",@"Snow Leopard",@"Lion",nil]; 
    self.projectArray = [[NSMutableArray alloc] initWithObjects:@"test1",@"test12",@"test1 Leopard",@"test13",nil];];  
    self.tblview.delegate= self; 
    self.tblview.dataSource=self; 
    self.tblviewProject.delegate= self; 
    self.tblviewProject.dataSource =self; 
    self.tblviewProject.frame = CGRectMake(50, 150, 600, 600); 
} 
-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 
- (NSUInteger) supportedInterfaceOrientations 
{ 
    return (UIInterfaceOrientationMaskLandscape); 
} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (tableView == self.tblview) 
    { 
    return [self.dataArray count]; 
    } 
    else if (tableView == self.tblviewProject) 
    { 
     return [self.projectArray count]; 
    } 
    return 0; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
    static NSString *CellIdentifier = @"Cell";  
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     cell.editingAccessoryType = YES; 
     if (tableView == self.tblview) 
     { 
      cell.textLabel.text = [self.dataArray objectAtIndex:indexPath.row]; 
     } 
     else if (tableView == self.tblviewProject) 
     { 
      cell.textLabel.text = [self.projectArray objectAtIndex:indexPath.row]; 
     }   
    } 
    return cell; 
} 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(tableView == self.tblviewProject) 
    {  
     NSMutableDictionary *newDic = [[NSMutableDictionary alloc] init]; 
     NSDictionary *rowchange = (NSDictionary *) [self.dataArray objectAtIndex:[self.projIndexPath intValue]]; 
     [newDic addEntriesFromDictionary:rowchange]; 
     [newDic setObject:pname forKey:project];  
     [self.tblview beginUpdates]; 
     [self.dataArray replaceObjectAtIndex:[self.projIndexPath intValue] withObject:newDic];   
     [self.tblview reloadData]; 
     [self.tblview endUpdates]; 
    } 
} 
@end  

enter image description here

+0

请使用您的问题下面的“编辑”链接属性格式代码并阅读指导原则。没有人可以阅读你发布的内容,因此对你没有帮助。 –

+0

请添加一个简短的描述,你想要达到什么样的目标,因为你的问题由于语法不好而不清楚。当用户单击第一个表格视图中的一行时,你想重新加载第二个表格视图? –

+0

第二个表格视图点击第一个表格视图重新加载。删除并创建工作正常。但不能替换或更改现有的记录值不会重新加载第一个表。 –

回答

-1

在你didSelectRowAtIndexPath方法FUNC,什么pnameprojIndexPath
而self.dataArray是NSString的数组,但你replaceObjectAtIndex与字典,这是不正确
我不知道你想要什么?

更新:你的功能乳宁,但并不意味着它是正确的
Cellforrowatindexpath设置

cell.textLabel.text = [self.dataArray objectAtIndex:indexPath.row]; 

但你在self.dataArray与字典替换项目==>你认为,这在工作吗?
尝试:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(tableView == self.tblviewProject) 
    { 
     [self.dataArray replaceObjectAtIndex:indexPath.row withObject:self.projectArray[indexPath.row]]; 
     [self.tblview reloadData]; 
    } 
} 

并根据需要更换pnam和projIndexPath

AXXXXXXXXXXX 更新cellforrowat

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     cell.editingAccessoryType = YES; 
    } 
    if (tableView == self.tblview) 
    { 
     cell.textLabel.text = [self.dataArray objectAtIndex:indexPath.row]; 
    } else if (tableView == self.tblviewProject){ 
     cell.textLabel.text = [self.projectArray objectAtIndex:indexPath.row]; 
    } 
    return cell; 
} 

我的肯定,这工作,当你reloaddata的实现代码如下,细胞不为零,所以,它不是单元格的设置数据

+0

pname表示tblviewProject选择索引值,projIndexPath表示tblview索引路径值。我的功能为replaceObjectAtIndex工作,但没有重新加载tblview。如何实现数据。请帮助我 –

+0

[self.dataArray replaceObjectAtIndex:indexPath.row withObject:self.projectArray [indexPath.row]]; [self.tblview reloadData]; \t \t \t \t它取代了dataArray对象索引,但没有重新传递tblview。请帮帮我。 –

+0

dataArray中(tblview1)和projectArray(tblview2) \t \t tblview2行值选择和改变tblview1第二索引值以下 \t \t是我的示例步骤 \t \t tblview1 itmes是TEST1,TEST2,TEST3,TEST4,TEST5,TEST6,TEST7 .... \t \t tblview2项newtest1,newtest2,newtest3,........ \t \t tblview2 - >选择newtest3值改变tblview1项是为test1,newtest3,TEST3,TEST4,TEST5,TEST6 ,test7 \t \t tblview2 - > select newtest1 values to change the tblview1 items are tes t1,newtest1,test3,test4,test5,test6,test7 –