0

カスタムセルを追加しています。誰かが追加ボタンを押すたびに、アラート ビューがポップアップ表示され、Web サイトの名前が追加されます。保存を押すと、選択した名前でテーブル ビュー セルに保存されます。次に、誰かがそのセルをクリックすると、Web ビューで http:// をロードします。唯一の問題は、ロードされていないことです。私は何を間違っていますか?

これは私のテーブルビューコントローラーです

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIdentifier = @"cellTwo";
    UITableViewCell *cell = [myTableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }

    if (indexPath.section == 0) {
        cell.textLabel.text = [NSString stringWithFormat:@"%@",[tableData objectAtIndex:indexPath.row]];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Index Selected,%d",indexPath.row);
    MainTwoViewController *View = [self.storyboard instantiateViewControllerWithIdentifier:@"mainTwo"];

    View.urlString = [[NSString alloc] initWithFormat:@"http://www.%@",tableData];
    View.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
}        

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    //Only do the following action if the user hits the ok button
    if (buttonIndex == 1) {
        NSString *tapTextField = [alertView textFieldAtIndex:0].text;
        if (!tableData) {
            tableData = [[NSMutableArray alloc]init];
        }
        [tableData insertObject:tapTextField atIndex:0];
        [myTableView reloadData];
}

そしてもちろん、これをmainTwoビューコントローラーに入れて、urlStringをロードします。

[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlString]]];
4

3 に答える 3

0

View Controller をインスタンス化しますが、表示しません。

代わりにストーリーボード セグエを使用し、新しいビュー コントローラを で構成しますprepareForSegue

また、次のことも確認してください。
ストーリーボードを使用している場合は、ほとんどの場合、 でセルを作成する必要はありませんcellForRowAtIndexPath

また、単純化します: -->
[NSString stringWithFormat@"%", string];
string

最後に、リクエストをロードする前に、新しいView Controllerに到着するURLを確認してください。URLが正しいことを確認してください。UIWebViewDelegateロードの失敗や予期しない戻りデータをチェックするメソッドを実装します。

于 2013-08-23T10:11:06.150 に答える
0

私はあなたのこのコードだと思います

View.urlString = [[NSString alloc] initWithFormat:@"http://www.%@",tableData];

のようにする必要があります

View.urlString = [[NSString alloc] initWithFormat:@"http://www.%@",[tableData objectAtIndex:indexPath.row]];

didSelectRowAtIndexPath メソッドで、また NSLog を使用して、どの時点でデータが失われたかを確認することをお勧めします

于 2013-08-23T11:18:37.547 に答える
-1

わかりました、私はあなたの問題を特定しました。

まず、カスタム セル ラベルにタップ ジェスチャを配置します。

UITapGestureRecognizer *openURLTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openURLTapped:)];

keypadDisableTapGestureRecognizer.numberOfTapsRequired = 1;
keypadDisableTapGestureRecognizer.numberOfTouchesRequired = 1;

[cell.textLabel addGestureRecognizer:openURLTapGestureRecognizer];

これで、このopenURLTappedに URL を渡して開くことができます。

-(void)openURLTapped:(UITapGestureRecognizer*)tap
{
    // your code here
}

それは間違いなくあなたの問題を解決します。

于 2013-08-23T10:08:48.790 に答える