0

I am trying to create a UITableView that lists each teacher in my school and acts as a link to each teacher's web page.

I have taken the HTML code off of the webpage and not have the list of teachers and page URLs.

To ensure privacy, the list code I am showing you is not real and the names and site addresses have been changed. It is an example, but is equivalent to what I am trying to do.

The list code is:

<div class="field-element"> <select name="" class="form-select launcher" id="" ><option value="0">-Select-</option><option value="/subsite/teacher/714">LastName, Firstname</option><option value="/subsite/teacher/286">LastName2, FirstName2</option><option value="/subsite/teacher/734">LastName3, FirstName3</option><option value="/subsite/teacher/513">LastName4, FirstName4</option></select>

with the /subsite/teacher/... code being the teacher page link appended to the URL www.website.com (resulting in www.website.com/subsite/teacher/... and the actual name of the teacher following that URL code in the HTML. This cycle repeats for each teacher.

How can I create an array of each teacher and the corresponding link for a UITableView from that HTML code? The UITableView would display the teacher's name in the format LastName, FirstName and when that cell is clicked, a UIWebView will open the corresponding web page.

Some example code would be greatly appreciated.

Note: Understand that the number of teachers could fluctuate, so it is not safe to assume the same number of teachers and the same names each time.

Thanks.

4
  • Is there some way you can contact the website administrator and arrange that they'd return you a JSON or XML object containing the list of teachers? Commented Feb 2, 2012 at 0:30
  • It could be done. Would I access that through some sort of URL? Commented Feb 2, 2012 at 0:34
  • It would look like this for instance: graph.facebook.com/19292868552. You send a request, receive a response with JSON object in it. Use SBJSON to convert JSON to NSDictionary and use the contents of the dictionary in your table view. Commented Feb 2, 2012 at 0:37
  • Eugene is correct. Sending the data in JSON format is a good way to send the data. However, you do not need to use SBJSON, as apple has now implemented JSON into Xcode already using the NSJSONSerialization class. Commented Feb 2, 2012 at 0:48

2 Answers 2

1

The general outline of the code could go this way:

  • Get the data from the site.
  • Parse the data to get each web-site. For this the easiest in my opinion is to use the NSString class and probably using the componentSeparatedByString:.
  • Generate an array of models or data-sources for the UITableView and populate it. Consider on the development of your model that you should not only include the name of the teacher but also the web-site as a property of that object.
  • Implement the didSelectRowAtIndexPath: method to respond to each cell by pushing a UIWebView initialized at the site corresponding to the teacher's website.

Hopefully this will help you.

Sign up to request clarification or add additional context in comments.

Comments

1
NSString *str=[your HTML];
int loc1=[str rangeOfString:@"value=" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [str length])].location;
int loc2= [str rangeOfString:@">" options:NSCaseInsensitiveSearch range:NSMakeRange(loc1, [str length])].location;
NSString *teacherSite=[str substringWithRange:NSMakeRange(loc1, loc2)];

this will give you teacher site link , do the same for the rest.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.