Iphone 奇数行为UIActionSheet+;UITableView:行消失

Iphone 奇数行为UIActionSheet+;UITableView:行消失,iphone,ios,core-data,uitableview,uiactionsheet,Iphone,Ios,Core Data,Uitableview,Uiactionsheet,我有一个UITableView,里面有一些静态单元格。其中一个触摸时显示UIActionSheet。下面是它的代码: viewDidLoad:初始化控件 - (void)viewDidLoad { [super viewDidLoad]; [self initializeControls]; } InitializeControl:将手势识别器添加到单元格内的标签,以显示UIActionSheet - (void)initializeControls { [...]

我有一个UITableView,里面有一些静态单元格。其中一个触摸时显示UIActionSheet。下面是它的代码:

viewDidLoad:初始化控件

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self initializeControls];
}
InitializeControl:将手势识别器添加到单元格内的标签,以显示UIActionSheet

- (void)initializeControls {
    [...]

    // Places Label
    self.placeNamesLabel.userInteractionEnabled = YES;
    tapGesture = \
    [[UITapGestureRecognizer alloc]
     initWithTarget:self action:@selector(didPlaceNamesLabelWithGesture:)];
    [self.placeNamesLabel addGestureRecognizer:tapGesture];
    tapGesture = nil;

    [...]
}
-(void)dismissPlacesActionSheet:(id)sender {
    [placesActionSheet dismissWithClickedButtonIndex:0 animated:YES]; }
DidPlaceNamesLabelWith手势:初始化UIActionSheet,从情节提要添加UITableView和关闭按钮

- (void)didPlaceNamesLabelWithGesture:(UITapGestureRecognizer *)tapGesture
{
    // Show UITableView in UIActionView for selecting Place objects.
    placesActionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                      delegate:nil
                                             cancelButtonTitle:nil
                                        destructiveButtonTitle:nil
                                             otherButtonTitles:nil];

    [placesActionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

    CGRect tableFrame = CGRectMake(0, 40, 0, 0);

    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    AddArticlesPlacesViewController *placesView = [storyBoard instantiateViewControllerWithIdentifier:@"PlacesForArticle"];
    placesView.managedObjectContext = self.managedObjectContext;
    placesView.view.frame = tableFrame;
    [placesActionSheet addSubview:placesView.view];
    placesView = nil;

    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]];
    closeButton.momentary = YES;
    closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
    closeButton.tintColor = [UIColor blackColor];
    [closeButton addTarget:self action:@selector(dismissPlacesActionSheet:) forControlEvents:UIControlEventValueChanged];
    [placesActionSheet addSubview:closeButton];
    closeButton = nil;

    [placesActionSheet showInView:[[UIApplication sharedApplication] keyWindow]];

    [placesActionSheet setBounds:CGRectMake(0, 0, 320, 485)];
}
dismissPlacesActionSheet:关闭UIActionSheet

- (void)initializeControls {
    [...]

    // Places Label
    self.placeNamesLabel.userInteractionEnabled = YES;
    tapGesture = \
    [[UITapGestureRecognizer alloc]
     initWithTarget:self action:@selector(didPlaceNamesLabelWithGesture:)];
    [self.placeNamesLabel addGestureRecognizer:tapGesture];
    tapGesture = nil;

    [...]
}
-(void)dismissPlacesActionSheet:(id)sender {
    [placesActionSheet dismissWithClickedButtonIndex:0 animated:YES]; }
一切正常,UITableView可以从核心数据中很好地填充。那么问题出在哪里呢?关键是当点击任何一行时,整个表都会变空(对不起,我还不能发布图像)

我尝试添加一个新的自定义行,该行带有一个按钮,可以向AddArticlesPlacesViewController触发一个推送序列;这工作正常,行为符合预期。因此,问题在于UIActionSheet和UITableView之间

以下是两个视图控制器的界面:

梅因

@接口AddArticleViewController:UITableViewController
[...]
@属性(弱,非原子)IBUILabel*placeNamesLabel;
@属性(强,非原子)NSManagedObjectContext*managedObjectContext;
[...]
@结束
次要的

@interface AddArticlesPlacesViewController : UITableViewController <NSFetchedResultsControllerDelegate>

@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;

@end
@interface AddArticlesPlacesViewController:UITableViewController
@属性(强,非原子)NSFetchedResultsController*fetchedResultsController;
@属性(强,非原子)NSManagedObjectContext*managedObjectContext;
@结束
我卡住了。我做错了什么

问候


Pedro Ventura.

您可以使用tableview的委托方法:

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

        NSLog(@"indexpath-->%d",indexPath.row);
        if (indexPath.row==0 || indexPath.row == 2 ) 
        {

            NSLog(@"row %d",indexPath.row);

        }

        if (indexPath.row==1)
     {

            actionsheet=[[UIActionSheet alloc]initWithTitle:@"Sample" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:nil, nil];
               [actionsheet showInView:self.view];

        }
    }
您可以对所选按钮使用UIActionsheetDelegate的方法:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
    {

         NSLog(@"index==>%d",buttonIndex);
           NSLog(@"cancel");
    }

是因为placesView托管对象上下文和placesView=nil吗?@verbumdei:我想不是,UITableView在两种解决方案(UIActionSheet内部和外部)中都显示了核心数据中的数据。我这样做了,在UIActionSheet中不会触发此事件。-(void)tableView:(UITableView*)tableView DidSelectRowatineXpath:(NSIndexPath*)indexPath{NSLog(@“Selected row%@”,indexPath);}应在使用UIActionSheet时不调用HighlightRowatineXpath、DidSelectRowatineXpath和DidSelectRowatineXpath;但是,是的,还有其他一些:numberOfSectionsInTableView,sectionIndexTitlesForTableView,numberOfRowsInSection,cellForRowAtIndexPath。