كيف أعرف في عرض التفاصيل ما هي الخلية في TableView التي تم اختيارها؟

StackOverflow https://stackoverflow.com/questions/2873745

سؤال

كيف يمكنني معرفة خلية TableView التي تم اختيارها؟ (كونها في عرض التفاصيل) المشكلة هي ذلك. لدي وحدة تحكم عرض الجدول. هنا يتم تحليلها من إدخالات الإنترنت إلى الطاولة. لذلك فهو طريقة عرض ديناميكية تابية يتم تحميلها من الإنترنت. لن أعرف عدد الإدخالات الموجودة في الجدول ، لذا لن أعرف ما هي التفاصيل التي يمكن الاتصال بها عند النقر فوق صف. لذلك قمت بتخويف وجهة نظر واحدة. هذا الرأي يحتوي على تقويم. في هذا التقويم (Wich هو التفاصيل IEW) ، سأقوم بتحليل البيانات من الإنترنت اعتمادًا على الصف المحدد. لـ exemple: لدي جدول: الإدخال 1 ، الإدخال 2 ، الإدخال 3 ، الإدخال 4 عند النقر فوق الإدخال 2 ، أحتاج إلى استدعاء PHP مع إدخال الوسيطة 2. سيعرف PHP الإدخال على الجدول الذي حددته وسأقوم بإنشائه لي XML الصحيح الذي سأحله.

إليكم وظيفة Didelectrow Tableview:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic -- create and push a new view controller

 if(bdvController == nil)
    bdvController = [[BookDetailViewController alloc] initWithNibName:@"BookDetailView" bundle:[NSBundle mainBundle]];
  Villa *aVilla = [appDelegate.villas objectAtIndex:indexPath.row];

  [self.navigationController pushViewController:bdvController animated:YES]

وهنا وظيفة العرض الذاتي الخاص بي على التفاصيل Conntroller:

-(void)loadView {

    [super loadView];

    self.title=@"Month"

    UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"ListView" style:UIBarButtonItemStyleDone target:self action:@selector(add:)];
    self.navigationItem.rightBarButtonItem = addButtonItem;

    calendarView = [[[KLCalendarView alloc] initWithFrame:CGRectMake(0.0f, 0.0f,  320.0f, 373.0f) delegate:self] autorelease];
    appDelegate1 = (XMLAppDelegate *)[[UIApplication sharedApplication] delegate];

    myTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 260, 320, 160)style:UITableViewStylePlain];
    myTableView.dataSource=self;
    myTableView.delegate=self;
    UIView *myHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, myTableView.frame.size.width,2)];
    myHeaderView.backgroundColor=[UIColor grayColor];
    [myTableView setTableHeaderView:myHeaderView];

    [self.view addSubview:myTableView];
    [self.view addSubview:calendarView];
    [self.view bringSubviewToFront:myTableView];
}

أعتقد أنه هنا في الحمل الذاتي ، أحتاج إلى إجراء الإجراء IF .. إذا كان indexpath.row = x parse fisier.php؟ variabila = title_of_rowx لكن السؤال هو كيف أعرف متغير indexpath؟

هل كانت مفيدة؟

المحلول

يمكنك تعيين خاصية على BookDetailViewController:

BookDetailViewController.h:

@interface BookDetailViewController : UITableViewController {
    NSIndexPath *selectedIndexPath;
}
@property (nonatomic, retain) NSIndexPath *selectedIndexPath;
@end

BookDetailViewController.M

@implementation BookDetailViewController
@synthesize selectedIndexPath;
- (void)dealloc {
    [selectedIndexPath release];
}
// ...
@end

TableView: DeSelectRowatIndexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic -- create and push a new view controller

    if(bdvController == nil) {
        bdvController = [[BookDetailViewController alloc] initWithNibName:@"BookDetailView" bundle:[NSBundle mainBundle]];
    }
    bdvController.selectedIndexPath = indexPath
    Villa *aVilla = [appDelegate.villas objectAtIndex:indexPath.row];

    [self.navigationController pushViewController:bdvController animated:YES]
}

اعتمادًا على ما تفعله في التطبيق الخاص بك ، قد يكون من المنطقي أن يجعل الممتلكات كائنًا فيلا بدلاً من nsindexpath.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top