小编sen*_*ion的帖子

如何为集合视图单元格内的视图添加手势?

我正在添加一个视图,该视图具有images(socialView)集合视图单元格内的一组视图(也具有其他视图),必须在该视图上执行公共单击。此单击不应与集合视图单元格单击相同。

我正在考虑在委托方法中添加UITapGestureRecognizerfor socialVieweverytime 。但我想知道这是正确的方法吗?此外,我想获取已被调用的索引路径/位置。CollectionViewcellForItemAtsocialView

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.socialViewTapped))

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "bidderAuctionCell", for: indexPath) as! BidderAuctionViewCell
     cell.socialView.addGestureRecognizer(tapGestureRecognizer)
}

@objc func socialViewTapped() {
     // Which item cell's socialview is clicked
}
Run Code Online (Sandbox Code Playgroud)

更新

我已按照以下建议完成,但我无法知道应该在自定义单元格中添加 UITapGestureRecognizer 的位置。以下是我创建的自定义单元格。

class CustomViewCell: UICollectionViewCell {

    var index : IndexPath!
    var socialViewDelegate : SocialViewDelegate!

    @IBOutlet weak var socialView: UIView!

    override init(frame: CGRect) {
        super.init(frame:frame)
        let tapGestureRecognizer …
Run Code Online (Sandbox Code Playgroud)

ios uitapgesturerecognizer uicollectionviewcell swift

5
推荐指数
1
解决办法
9891
查看次数

在while循环中'n'次后中断UL标记

我目前正在为我工​​作的公司开发模块商店,并且存在一些问题.从表中提取记录时,我希望每隔三个数据记录关闭HTML"UL"标记.

这就是我目前拥有的:

<?php
  $selektKat = "SELECT * FROM `proizvodi` WHERE `kategorija` = '$kat'"; //don't worry about SQLi; I will fix it
  $result = mysqli_query($con, $selektKat) or die(mysqli_error());

// Line where the loop starts
<?php
while ($row = mysqli_fetch_array($result)) { ?>

  <ul class="products-grid clearfix" style="margin-right: 5px; margin-left: 20px;">
  <li class="item" style="min-height: 339px">
    <a id="product-image-42321" href="proizvod.php" title="naziv" class="product-image">
      <img src="http://static.511tactical.com/mag/media/catalog/product/cache/1/small_image/220x/9df78eab33525d08d6e5fb8d27136e95/5/3/53212_716_Alternate1.jpg" width="220" alt="<?php echo $row['naziv'] ?>" />
    </a>
      <ul class="swatches clearfix">
      <li id="swatch-228" class="swatch product-42321">
        <a href="proizvod.php" title="<?php echo $row['naziv']; ?>">
        <img src="<?php …
Run Code Online (Sandbox Code Playgroud)

php

3
推荐指数
1
解决办法
2017
查看次数

从BeautifulSoup结果中获取表单"动作"

我正在为一个网站编写一个Python解析器来自动完成一些工作,但我对Py的"re"模块(正则表达式)并不多,并且无法使其工作.

req = urllib2.Request(tl2)
req.add_unredirected_header('User-Agent', ua)
response = urllib2.urlopen(req)
try:
    html = response.read()
except urllib2.URLError, e:
    print "Error while reading data. Are you connected to the interwebz?!", e

soup = BeautifulSoup.BeautifulSoup(html)
form = soup.find('form', id='form_product_page')
pret = form.prettify()

print pret
Run Code Online (Sandbox Code Playgroud)

结果:

<form id="form_product_page" name="form_1362737440" action="/download/791055/164084/" method="get">
<input id="nojssubmit" type="submit" value="Download" />
</form>
Run Code Online (Sandbox Code Playgroud)

确实,代码已经完成,正是我需要的开始.现在,我想知道从"form"标签中提取"action"属性的方法.这只是我从BeautifulSoup响应中所需要的.

我尝试过使用form = soup.find('form', id='form_product_page').parent.get('action')但是结果是"无".我想要提取的是例如"/ download/791055/164084 /".链接的每个URL都有所不同.


变量(示例):
tl2 = http://example.com
ua = Mozilla Firefox/14.04

python regex beautifulsoup web-scraping

2
推荐指数
1
解决办法
7352
查看次数