开发者

Problem using the index of a UITableView to change a String

I'm fairly new to iPhone programming and I have a project that needs to be completed soon. I am trying to use a UITableView to list three websites and then load up to desired website on selection. This is the code I have so far:

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


    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];

    if (storyIndex = 1) {
        venueLink = @"http://kos-mediadesign.com/Storage/IconVenues/IconVenue.html";
    }

    else if (开发者_高级运维storyIndex = 2) {
        venueLink = @"http://kos-mediadesign.com/Storage/IconVenues/SmythsVenue.html";
    }

    else if (storyIndex = 3) {
        venueLink = @"http://kos-mediadesign.com/Storage/IconVenues/SinnotsVenue.html";
    }
}

No matter what site I select the first one is always opened in my DetailView. I would really appreciate some help on this.

Thanks, Kev


You are missing an equal sign.

= is assigning Value

== is comparing

try

 int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];

    if (storyIndex == 1) {
        venueLink = @"http://kos-mediadesign.com/Storage/IconVenues/IconVenue.html";
    }

    else if (storyIndex == 2) {
        venueLink = @"http://kos-mediadesign.com/Storage/IconVenues/SmythsVenue.html";
    }

    else if (storyIndex == 3) {
        venueLink = @"http://kos-mediadesign.com/Storage/IconVenues/SinnotsVenue.html";
    }


This:

if (storyIndex = 1) {

sets the value of storyIndex to 1.

This:

if (storyIndex == 1) {

tests whether the value of storyIndex is 1. Switch to double equals signs and your code will work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜