ruby-****@sourc*****
ruby-****@sourc*****
2012年 8月 26日 (日) 08:36:25 JST
------------------------- REMOTE_ADDR = 70.49.49.99 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-addrnhs ------------------------- @@ -560,7 +560,7 @@ After we know we have legitimate data from the data entry dialogue, we need to prepare to traverse through our tree store searching for the matching product category. We start searching at the top of the tree store: model = treeview.model - iter = model.get_iter("0") + iter = model.iter_first #<-- same as: iter = model.get_iter("0") In the first line above we conveniently tuck away the model separating data store from the view (MVC). We use model to get to the starting iterator, by supplying the top-level root path "0". Then comes a tricky while loop, where we want to process the first iteration with the iter we have just obtained, while at the same time use Gtk::TreeIter#next! as the condition in the while loop. The API for Gtk::TreeIter#next! tells us that this command returns true if the iterator was successfully advanced and false otherwise. In this case (if false is returned the iterator will point again to the first item in the tree store). Of course, the most important part of this loop is the break statement, which abandons the loop leaving the iterator to point to the product category we were looking for.